0

Is there a way to generate models and associations (through automation) based on an existing database?

For example, take customers and orders:

Customer
---------
id, name

Order
---------
id, customerId, orderDate
Rod
  • 14,529
  • 31
  • 118
  • 230

1 Answers1

0

I think you can use Sequelize-Auto for this

Automatically generate models for SequelizeJS via the command line.

Command for that :

[node] sequelize-auto -h <host> -d <database> -u <user> -x [password] -p [port]  --dialect [dialect] -c [/path/to/config] -o [/path/to/models] -t [tableName] -C

TUTORIAL LINK

Vivek Doshi
  • 56,649
  • 12
  • 110
  • 122
  • I've used this but it does not pick up the associations unless I'm not doing something right. – Rod Aug 28 '18 at 03:25
  • Try https://github.com/gbahamondezc/sequelize-models. It says it generates associations but right now it will not run for me. See https://github.com/gbahamondezc/sequelize-models/issues/10 – dan Apr 10 '19 at 04:48