Search code examples
javascriptnode.jspostgresqlsequelize.jssequelize-cli

Sequelize seeders are working but next time I am getting error


Seeders files are working fine first time but not second time I got the reason of this issue. Its happening because seeders are not keeping any record of already executed files like migration keep the record of executed file in sequelizeMeta. I read somewhere that for seeders sequelize create sequelizeData table to keep record of executed files but in my case there is no sequelizeData table due to this I think I m getting error. use already executed files are executing again and I am getting unique key constraint and this error blocks whole pipeline

Help me please I stucked in this issue since a long


Solution

  • Unlike for migrations Sequelize doesn't store any info about executed seeders in DB by default, see the Sequelize CLI documentation

    Seed
    By default the CLI will not save any seed that is executed. If you choose to change this behavior (!), you can use seederStorage in the configuration file to change the storage type. If you choose json, you can specify the path of the file using seederStoragePath or the CLI will write to the file sequelize-data.json. If you want to keep the information in the database, using sequelize, you can specify the table name using seederStorageTableName, or it will default to SequelizeData.

    {
      "development": {
        "username": "root",
        "password": null,
        "database": "database_development",
        "host": "127.0.0.1",
        "dialect": "mysql",
        // Use a different storage. Default: none
        "seederStorage": "json",
        // Use a different file name. Default: sequelize-data.json
        "seederStoragePath": "sequelizeData.json",
        // Use a different table name. Default: SequelizeData
        "seederStorageTableName": "sequelize_data"
      }
    }