Reputation: 2154
I have a database already built and I am using it with Sequelize ORM. The database already has timestamp columns as "created_at" and "updated_at".
To generate sequelize Models I used sequelize-auto and it generated all the models with one command. But when I use any model to fetch data. It returns error "unknown column createdAt".
Therefore I manually opened a model file and edited it with "underscored: true" and it solved the problem. But I want this option to be set globally for all models. Therefore after googling for some time I came to know about -c option with "sequelize-auto" command.
So I created a json file and passed the path to this file in -c option. But again all the models were without "underscored: true" option.
I used this option as follows
sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -x my_password -e mysql -c ./config/config.json
I also used this command with quotes
sequelize-auto -o "./models" -d sequelize_auto_test -h localhost -u my_username -x my_password -e mysql -c "./config/config.json"
Upvotes: 4
Views: 2505
Reputation: 41
Use the -a (--additional) flag instead of the -c to include additional model options from your JSON file.
This is what the command line help says:
-a, --additional Path to a json file containing model definitions (for
all tables) which are to be defined within a model's
configuration parameter. For more info:
https://sequelize.readthedocs.org/en/latest/docs/models
-definition/#configuration
Upvotes: 4
Reputation: 146
You have to write down your ./config/config.json just simple:
{
"underscored": true
}
On my case, i'm already have the created_at and updated_at, so lets the sequelize not retrieve automatically and including schema, i have to set on my config :
{
"timestamps": false,
"schema": "sch_hrms"
}
then, execute again sequelize-auto.
All models will auto include that options.
-ManzTIHAGI
Upvotes: 3