Cli: sequelize model:create --name "Person", but generate "People"

Created on 21 Jan 2019  Â·  6Comments  Â·  Source: sequelize/cli

I run this command: $ sequelize model:create --name "Person", but generate the name "People"

20190121082004-create-person.js

module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('People', {

Even if i change People to Person, i got some error when i was run: $ sequelize db:migrate

Unhandled rejection SequelizeDatabaseError: Table 'demodb.people' doesn't exist

Is there anyone got the same with me ?

stale

Most helpful comment

@tsurumure

I think it's due to the freezeTableName flag from Configuration, it reads as follows:

You can also influence the way Sequelize handles your column names:

const Bar = sequelize.define('bar', { /* bla */ }, {
...
 // disable the modification of table names; By default, sequelize will automatically
 // transform all passed model names (first parameter of define) into plural.
 // if you don't want that, set the following
 freezeTableName: true,

By default, the value is false (Sequelize will pluralize table names).

1) Try setting freezeTableName: false on your model/person.js.

I don't know the CLI command. Will look up later if I have a chance.

All 6 comments

Greetings.

  1. Please run $ sequelize db:migrate:undo to undo the migration before running it again.

Explanation:

  • If the migration has been executed, an entry will be added to your SequelizeMeta table. As long as it is there, running it again will yield no changes. Use db:migrate:undo to undo the migration.
  • If you manually delete the entry, or delete the table, it may cause problems to do/undo migrations.
  • The "do" migration is named "up".
  • The "undo" migration is named "down".
  • If there is no "down", db:migrate:undo will not work.

The model at models/person.js is meant to be used for an ORM environment. Please also consider updating it properly.

Please also consider reading the tutorial docs fully.

Thanks for reply. @KinoshitaShimizu
I found that when i create a name man, will change to men, so i think that is some kind of rule,
but i still can't found it in the docs.

@tsurumure

I think it's due to the freezeTableName flag from Configuration, it reads as follows:

You can also influence the way Sequelize handles your column names:

const Bar = sequelize.define('bar', { /* bla */ }, {
...
 // disable the modification of table names; By default, sequelize will automatically
 // transform all passed model names (first parameter of define) into plural.
 // if you don't want that, set the following
 freezeTableName: true,

By default, the value is false (Sequelize will pluralize table names).

1) Try setting freezeTableName: false on your model/person.js.

I don't know the CLI command. Will look up later if I have a chance.

Great help, thanks!

For cli, in models/index.js
config.freezeTableName = true;

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

Related issues

LucasBadico picture LucasBadico  Â·  5Comments

LoneWolfPR picture LoneWolfPR  Â·  5Comments

f1nnix picture f1nnix  Â·  4Comments

Jakobud picture Jakobud  Â·  4Comments

shomanishikawa picture shomanishikawa  Â·  3Comments