Sequelize / js / bot / errors

New file.sqlite database files are now created empty and are invalid.
Every twitch chat or discord chat message causes an error.

(node:695) UnhandledPromiseRejectionWarning: SequelizeDatabaseError: SQLITE_ERROR: no such table: customs
at Query.formatError (/rbd/pnpm-volume/4f6c3f9f-debe-43cb-8620-073ae5f3fcbd/node_modules/.registry.npmjs.org/sequelize/5.16.0/node_modules/sequelize/lib/dialects/sqlite/query.js:419:16)
at Query._handleQueryResponse (/rbd/pnpm-volume/4f6c3f9f-debe-43cb-8620-073ae5f3fcbd/node_modules/.registry.npmjs.org/sequelize/5.16.0/node_modules/sequelize/lib/dialects/sqlite/query.js:73:18)
at afterExecute (/rbd/pnpm-volume/4f6c3f9f-debe-43cb-8620-073ae5f3fcbd/node_modules/.registry.npmjs.org/sequelize/5.16.0/node_modules/sequelize/lib/dialects/sqlite/query.js:247:31)
at Statement.errBack (/rbd/pnpm-volume/4f6c3f9f-debe-43cb-8620-073ae5f3fcbd/node_modules/.registry.npmjs.org/sqlite3/4.1.0/node_modules/sqlite3/lib/sqlite3.js:16:21)
(node:695) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:695) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

MOD EDIT: formatting

Hi @AndriyMeleshko, welcome to the Glitch forum!

That message indicates that your database is findable but doesn’t include the table you’re looking for, which I believe you’ve understood. In order for us to help, though, I think we’ll need to understand more about how your database files are created. Can you provide your project name so that folks can take a look at your code, or barring that at least post the code that you expect to be creating those database files?

Hello @cori
It used to be okay. Recently, database files are created empty. On the computer it works.
The creation is automatic. Table.

const Sequelize = require('sequelize')
const sequelize = new Sequelize('data', 'user', 'password', {
  host: 'localhost',
  dialect: 'sqlite',
  logging: false,
  storage: './discord/commands/custom/data.sqlite'
})
const custom = sequelize.define('custom', {
  name: Sequelize.STRING,
  description: Sequelize.TEXT,
  username: Sequelize.STRING,
  channelname: Sequelize.STRING,
  guildname: Sequelize.STRING,
  guildid: Sequelize.STRING,
  cooldown: Sequelize.STRING,
  usage_count: {
    type: Sequelize.INTEGER,
    defaultValue: 0,
    allowNull: false
  }
})
module.exports = { custom }

MOD EDIT: formatting

In the code you posted you’re initializing a table called custom but in the error message your code is looking for a table called customs. Is it possible there’s a table name mismatch somewhere else in your code?

In the error message “s” is appended to all table names.

Did you maybe move the code that runs this, to another folder? The dot in the path means “current directory”, so this path may have changed by rearranging the code. Could try a path of /app/discord/commands/custom/data.sqlite

Don’t forget to add your data folders to .gitignore.

That occurred to me as well, but the path resolution may be from where the top-level code is being called from and not where the code that’s accessing the database files is located. Also I’d expect a different error message if the data file just can’t be found. It’s definitely worth trying the absolute path, I just wouldn’t expect it to resolve the issue.

I’m curious if there’s anything else in the logs around the snippet you’ve shared thus far, @AndriyMeleshko, that might point us to the place in your code that the sequelize promise that’s being rejected is called. If you want to share your project name we can also take a look at the code and errors in context.

SQLite is often setup so that if the data file is not found, it automatically creates a new one. Then, if the table names in the auto create code are different from those in the query code, the error about no such table would occur.

1 Like

Hello @mishavee @cori
I used “Rewind” to restore old database files.
Only one didn’t work. I was surprised but it started working. The address of this file is ./twitch/welcome/data.sqlite
Unfortunately, files that are automatically created are visible in a few hours.
My project: https://glitch.com/~carlita
Channel for commands testing: https://www.twitch.tv/carlita_desperado
Sorry, but the answers are in Ukrainian.
I’ll try the way later /app/discord/commands/custom/data.sqlite
Thanks for the tips!

I don’t understand where the error was. There was an error in my project or not. New database files are currently being created and running.

1 Like

Hello @cori and @mishavee
I’m not sure, but it may be my mistake.
When I forget to add “.sync ()”, I get the same error.
Thanks for your time and tips. Sorry.

1 Like