Cli: can't run seeder

Created on 12 Jul 2016  Â·  14Comments  Â·  Source: sequelize/cli

i'm trying to run this simple seeder

'use strict';

module.exports = {
    up(queryInterface) {
        return queryInterface.bulkInsert('Users',
            [{
                username: 'aaaa',
                password: 'qweqwe',
                email: '##',
                profile: {
                    name: 'aaa',
                    surname: 'bbb',
                },
                createdAt: Date.now(),
                updatedAt: Date.now(),
            }, {
                username: 'ccc',
                password: 'qweqwe',
                email: '##',
                profile: {
                    name: 'ddd',
                    surname: 'eee',
                },
                createdAt: Date.now(),
                updatedAt: Date.now(),
            }]
        );
    },

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

⇒ sequelize db:seed:all

Sequelize [Node: 6.3.0, CLI: 2.4.0, ORM: 3.23.3, pg: ^6.0.1]

(node:31807) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Loaded configuration file "config/config.json".
Using environment "development".
== 20160711203859-users-seeder: migrating =======
Seed file failed with error: val.replace is not a function

i tried to debug but couldn't follow track down the call.
what am i doing wrong ?

also i use this return queryInterface.bulkInsert('Users', [{}]); as up()

this is the result

⇒ sequelize db:seed:all

Sequelize [Node: 6.3.0, CLI: 2.4.0, ORM: 3.23.3, pg: ^6.0.1]

(node:32089) fs: re-evaluating native module sources is not supported. If you are using the graceful-fs module, please update it to a more recent version.
Loaded configuration file "config/config.json".
Using environment "development".
== 20160711203859-users-seeder: migrating =======
Seed file failed with error: syntax error at or near ")"

Most helpful comment

I would love to see an update on this issue, because this also fails when I am trying to seed PostGIS location data.

return queryInterface.bulkInsert('place', [{
  key: 'foo-bar',
  name: 'Foo Bar',
  location: { type: 'Point', coordinates: [ 20.123, 60.123] },
}]);

All 14 comments

Same here.

Sadly enough, using the same code in a migration, works fine.

@mickhansen @janmeier Any ideas on how to debug it? I can happily dig on this to fix it.

I dig a little more and found that the error (in my case and probably yours too) is caused by the appearance of a nested object in the bulkInsert data, as profile is.

The following error is triggered when I remove the catch clause, which doesnt give much info about it:

Unhandled rejection TypeError: val.replace is not a function
    at SqlString.escape (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/sql-string.js:63:15)
    at wrapper (/home/diosney/Projects/booking-api/node_modules/sequelize/node_modules/lodash/lodash.js:4663:19)
    at Array.map (native)
    at Object.SqlString.escape (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/sql-string.js:55:16)
    at Object.QueryGenerator.escape (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/dialects/abstract/query-generator.js:977:22)
    at Object.<anonymous> (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/dialects/abstract/query-generator.js:356:23)
    at Array.map (native)
    at Object.<anonymous> (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/dialects/abstract/query-generator.js:352:23)
    at Array.forEach (native)
    at Object.QueryGenerator.bulkInsertQuery (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/dialects/abstract/query-generator.js:350:21)
    at QueryInterface.bulkInsert (/home/diosney/Projects/booking-api/node_modules/sequelize/lib/query-interface.js:568:33)
    at Object.module.exports.up (/home/diosney/Projects/booking-api/seeders/20160727222414-unnamed-seeder.js:30:27)
    at module.exports.redefine.Class._exec (/home/diosney/Projects/booking-api/node_modules/umzug/lib/migration.js:103:23)
    at module.exports.redefine.Class.up (/home/diosney/Projects/booking-api/node_modules/umzug/lib/migration.js:69:17)
    at .<anonymous> (/home/diosney/Projects/booking-api/node_modules/umzug/index.js:124:28)
    at PassThroughHandlerContext.finallyHandler (/home/diosney/Projects/booking-api/node_modules/bluebird/js/release/finally.js:56:23)

It seems that at sequelize/lib/sql-string.js:63:15 it threw the error due invoking replace, a String method, in the passed Object, which doesnt have it.

In my case all is reduced on the following question:

How insert associated data with the bulkInsert method in the same query to not have to do two separated queries?

I'm running into the same issue. Any progress on this?

I ended up with separated seeders for the nested data., just in case it solves your issue.

I would love to see an update on this issue, because this also fails when I am trying to seed PostGIS location data.

return queryInterface.bulkInsert('place', [{
  key: 'foo-bar',
  name: 'Foo Bar',
  location: { type: 'Point', coordinates: [ 20.123, 60.123] },
}]);

Closing (Issue Cleanup), Please comment if you want to keep it open

This issue still persists. Seeders were working properly. But weirdly it is throwing Unexpected token or identifier. I tried to remove all ES6 code, then it works. If I have ES6 code in migrations, it works without any issues. Please reopen this.

@AshwinTayson

I tried to remove all ES6 code, then it works. If I have ES6 code in migrations, it works without any issues.

This is contradictory, please clarify, thanks!

@papb I don't think it's contradictory. I'm having the same issues and I don't know how else to explain it. No issues with ES6 when running migrations but using the same syntax and format for seeders causes problems. When removing ES6 in seeders, it works.

Ah, I think I get it now:

  • ES6 code works at migrations
  • ES6 code doesn't work at seeders

@dkayzee is this correct?

Ah, I think I get it now:

  • ES6 code works at migrations
  • ES6 code doesn't work at seeders

@dkayzee is this correct?

Yes that's correct

@papb yes that is correct! sorry i didn't get back to this. Thanks @AshwinTayson

To solve this, npm install --save-dev @babel/register then in your .sequelizerc file put this on top
require("babel-register");

Was this page helpful?
0 / 5 - 0 ratings

Related issues

PavelPolyakov picture PavelPolyakov  Â·  5Comments

shomanishikawa picture shomanishikawa  Â·  3Comments

arndeash picture arndeash  Â·  3Comments

KaltZK picture KaltZK  Â·  5Comments

eharoldreyes picture eharoldreyes  Â·  3Comments