Cli: Seed doesn't execute, marked as succeeded

Created on 11 May 2016  Â·  19Comments  Â·  Source: sequelize/cli

I've been struggling with this for almost an entire day. The TL;DR is that all of the db:seed commands will execute and _not throw an error when they don't actually do anything_. I've been pulling my hair out trying to figure out what the hell is going on but since there's no real documentation, it's been extremely tough.

None of the seed commands ever work. Not seed --seed, not seed:undo, not seed:all (no seeds! great!), not seed:undo:all (again there are no seeds! wat). I switched to the json seeder cache and have been manually modifying it because even though the seed _doesn't do anything_ it gets marked as complete.

Seeders that don't execute should not be marked as a success. And I know it didn't execute because I have no data in my database (I had to remove it all manually because again undo doesn't work).

'use strict';

module.exports = {
  up: function (queryInterface, Sequelize) {
    return 
      queryInterface.bulkInsert('Users', [
        {email: "[email protected]", name: "Aphrodite",  createdAt: Date.now(), updatedAt: Date.now() },
        {email: "[email protected]", name: "Athena", createdAt: Date.now(), updatedAt: Date.now() },
        {email: "[email protected]", name: "Zeus", createdAt: Date.now(), updatedAt: Date.now() },
        {email: "[email protected]", name: "Apollo", createdAt: Date.now(), updatedAt: Date.now() }
        ]
      );
  },

  down: function (queryInterface, Sequelize) {
    return 
    queryInterface.bulkDelete('Users', null, {});
  }
};

I do not have a schema. I've tried wrapping the returned queryInterface in an array as some Stack Overflow posts have suggested, nothing. I've tried {tableName: 'Users'} and nothing. I've tried an empty string schema, also nothing. I've added a {schema: 'whatever'} after the data array, nothing. I added an empty hash after the data array, nothing. So something is going on but it's just not executing my inserts or deletes, and it's not telling me there's an error. Silence is the absolute worst thing.

This is with Sequelize 3.23.0, CLI 2.4.0

investigate stale

Most helpful comment

Just curious, but is the empty space after return causing a JS bug?
http://encosia.com/in-javascript-curly-brace-placement-matters-an-example/

All 19 comments

Just curious, but is the empty space after return causing a JS bug?
http://encosia.com/in-javascript-curly-brace-placement-matters-an-example/

@jocull great catch! Tested it in my code and you are absolutely right. The seed just returns instantly.

@Americas Thanks, I thought that might be it. :) I actually came to this issue looking for why my seeders had stopped recording their runs in my database. What I ended up discovering is that the "seederStorage" is now none by default. I had to manually set this to "seqeulize" to make them start storing again. This is a big breaking change on a minor version increase, as my database now seeds over and over until I stop it. Could these please be major version bumps in the future?

@mtitolo This almost certainly something a linter would catch in the future. Hope that helps :)

That fixes db:seed but none of the other commands work.

@mtitolo Try setting your "seederStorage" like I mentioned above. If nothing is being recorded, you may not have anything to :undo

sequelize-data.json:

[
  "20160511015238-users-and-groups.js"
]

config.json:

  "development": {
    "dialect": "sqlite",
    "storage": "./db.development.sqlite",
    "seederStorage": "json",
    "host": "127.0.0.1"
  },

undo:all outputs a different error:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

And when I clear the DB/seederStorage and try to run seed:all:

$ node_modules/.bin/sequelize db:seed:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

None of the :all methods work.

Edit: Apparently :undo needs to pass in a seed name. That makes no sense as I just want to undo the one and only change.

Is it possible that the seeder path is looking in the wrong place? Where
are your seeders stored relative to your project root?

On Thu, May 12, 2016 at 11:14 AM, Michele [email protected] wrote:

sequelize-data.json:

[
"20160511015238-users-and-groups.js"
]

config.json:

"development": {
"dialect": "sqlite",
"storage": "./db.development.sqlite",
"seederStorage": "json",
"host": "127.0.0.1"
},

$ node_modules/.bin/sequelize db:seed:undo

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
Unspecified flag "seed". Check the manual for further details.

undo:all outputs a different error:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

And when I clear the DB/seederStorage and try to run seed:all:

$ node_modules/.bin/sequelize db:seed:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
No seeders found.

None of this works.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/sequelize/cli/issues/301#issuecomment-218789051

They are in seeders/

Can you try turning on logging? This is why my .sequelizerc file looks like. You might be able to cut it down to just module.exports.logging = true but I'm not sure what all is required.

'use strict'

var path = require('path')
var config = require('config')

config.database.config = __filename

module.exports = config.database
module.exports['migrations-path'] = 'build/migrations'
module.exports['seeders-path'] = 'build/seeders'
module.exports.logging = false

Derp, you probably just need to set logging = true in your config...

Magically :seed:all started working. I didn't change anything. This makes no sense. This is ridiculous.

And there's no real info on why undo:all isn't working:

$ node_modules/.bin/sequelize db:seed:undo:all

Sequelize [Node: 5.10.1, CLI: 2.4.0, ORM: 3.23.0]

Loaded configuration file "config/config.json".
Using environment "development".
DEPRECATION WARNING: The logging-option should be either a function or false. Default: console.log
Executing (default): SELECT 1+1 AS result
No seeders found.

Strange, I wonder what this means?

Executing (default): SELECT 1+1 AS result

WAIT I did change something. I dropped the table in the DB that used to store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in json, :seed:all will not work. Without the table, :seed:all works. :undo:all still doesn't work with or without the table when json is the seederStorage.

If I use sequelize as the seederStorage the commands all work as expected. Something is up with the JSON seederStorage setting that's causing the commands to fail.

That should help narrow it down at least! I have been using sequelize for
seederStorage and that fixed my original issue, but the semantics of this
have changed significantly over the past few minor version releases. (Which
is what I was trying to point out earlier)

On Thu, May 12, 2016 at 11:31 AM, Michele [email protected] wrote:

WAIT I did change something. I dropped the table in the DB that used to
store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in
json, :seed:all will not work. Without the table, :seed:all works.
:undo:all still doesn't work with or without the table when json is the
seederStorage.

If I use sequelize as the seederStorage the commands all work as
expected. Something is up with the JSON seederStorage setting that's
causing the commands to fail.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/sequelize/cli/issues/301#issuecomment-218794373

I did just try to run sequelize db:seed:undo:all with sequelize
seederStorage and that did nothing, however. I don't usually try to undo,
so I hadn't uncovered this before.

On Thu, May 12, 2016 at 11:35 AM, James O'Cull [email protected] wrote:

That should help narrow it down at least! I have been using sequelize
for seederStorage and that fixed my original issue, but the semantics of
this have changed significantly over the past few minor version releases.
(Which is what I was trying to point out earlier)

On Thu, May 12, 2016 at 11:31 AM, Michele [email protected]
wrote:

WAIT I did change something. I dropped the table in the DB that used to
store the changes instead of the JSON file.

So if there's a SequelizeData table and I'm storing seed migrations in
json, :seed:all will not work. Without the table, :seed:all works.
:undo:all still doesn't work with or without the table when json is the
seederStorage.

If I use sequelize as the seederStorage the commands all work as
expected. Something is up with the JSON seederStorage setting that's
causing the commands to fail.

—
You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/sequelize/cli/issues/301#issuecomment-218794373

Looks like there are lots of issues with seeders right now. #403 #408

Is there anything like umzug for running seeders programatically rather than via the cli?

Seeds are applied in order so if I want seed:undo to always undo the recent migration I use this script entry from my package.json:

"seed:down": "sequelize --seed $(ls ./src/seeds | sort | tail -n 1) db:seed:undo"

But you have to keep in mind before running that you applied all pending seeds, otherwise it'll try to undo a seed that hasn't been applied and that can cause unexpected result depending on that migration's down method.

I know this is an old issue but I had a very similar issue and this thread kept coming up when I searched for answers. My problem was I was trying to run a seeder file and it was completing but not actually populating my table. The problem came from the seeder file trying to populate a field that didn't exist. It didn't give me any error. Hope this helps someone else.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings