0

I want to sync all table a.k.a create table if not exists. i follow this official tutorial rather than call sync one by one each model. theres single call can sync all. sequelize.sync() but it do nothing. i try to try catch no error too. current sequelize version 6.25.2. setup.js to action to create table. its like sequelize instance doesn't resolve model.

sequelize-client.js

const sequelize = new Sequelize(username, password, database);
export { sequelize }

models folder user.js

import { sequelize } from "sequelize-client.js";
const User = sequelize.define("User",  {
    id: {
        type: BIGINT.UNSIGNED,
        autoIncrement: true,
        primaryKey: true
    },
    username: {
        type: STRING,
        allowNull: false
    },
    password: {
        type: STRING,
        allowNull: false
    }
});

models folder account.js

const Account = sequelize.define("Account", {
    id: {
        type: BIGINT.UNSIGNED,
        autoIncrement: true,
        primaryKey: true
    },
    accoundId: {
        type: STRING,
        allowNull: false
    },
    createdAt: {
        type: DATE,
        allowNull: false
    }
});

setup.js

import { sequelize } from "sequelize-client.js";
sequelize.sync({ force: true });
yurayura
  • 1
  • 2

1 Answers1

0

In order to create tables properly using sync method of Sequelize instance you need to register all models and their associations prior to calling sync. I recommend to look at my answer here to find out how to do it.

Anatoly
  • 20,799
  • 3
  • 28
  • 42