Skip to content

Trying to initialize a database results in: SequelizeDatabaseError: SQLITE_ERROR: no such table: Users #874

@rdvhoorn

Description

@rdvhoorn

Have been rewriting a backend using sequelize in typescript, and recently discovered this beauty of a library. Loving it so far, but running into a problem. Thus beware for noob mistakes, but cant seem to figure this one out myself.

Versions

  • sequelize: 5.22.3
  • sequelize-typescript: 1.1.0
  • typescript: 3.9.7

Have set up all my models now with sequelize-typescript. Have my db.ts file for creating my database:

const storage = "data.sqlite";
export const db: Sequelize = new Sequelize({
    database: "db",
    dialect: "sqlite",
    username: null,
    password: null,
    storage,
});

/** lots of import **/

db.addModels([Activity, User, ... More models ...]);

For running and testing the server, we always had a script that initialized the instance of the database (data.sqlite file) and imported the first few instances of each of the models for easy testing. Im trying to get this to work now, but running into some problems. In this script, we first define the stuff we want to initialize in arrays and then call bulkCreate on the models like this:

all([
    Role.bulkCreate(roles).then(function(result: any): void {
        console.log("Created roles");
    }),
    User.bulkCreate(users).then(function(result: any): void {
        console.log("Created users");
    }),
    Group.bulkCreate(groups).then(function(result: any): void {
        console.log("Created groups");
    }),
    Activity.bulkCreate(activities).then(function(result: any): void {
        console.log("Created activities");
    })
]).then(function(): any { /** more stuff **/}

Whenever running this (running it using: npx ts-node src/import_initial.ts), it logs Executing (default): INSERT INTO 'Users' ..... and then shows all the correct information, after which it gives an error message SequelizeDatabaseError: SQLITE_ERROR: no such table: Users. To what I understand, the User model should create a table in the db called User and not Users. I already tried to force the name of the table, but the same error persists. The problem seems to be that the model is added to the sequelize instance, but the table is not created. Anybody knows how to solve this? Thanks a lot in advance!

If you want to see the full code: https://github.com/Confluente/backend-v2/tree/sequelize-typescript-implementation (don't look too much around yet :P routes and stuff still needs to be rewritten. But with db.ts, all the models, and the import_initial.ts script you should have everything that regards my current question.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions