Skip to content
This repository has been archived by the owner on Apr 3, 2022. It is now read-only.

Specifying associations via migrations #176

Closed
jonlambert opened this issue Jun 25, 2015 · 3 comments
Closed

Specifying associations via migrations #176

jonlambert opened this issue Jun 25, 2015 · 3 comments

Comments

@jonlambert
Copy link

When defining a migration, how can I specify a relationship to another Model (thus creating the valid foreign keys)?

There's plenty of documentation for adding this via .sync(), but none that I can find for adding via migrations.

@cusspvz
Copy link

cusspvz commented Jun 25, 2015

Hey @jonlambert ,
I'm using sequelize for about 2 years, and in the past I had loaded models on migrations until I had experienced some problems with that. Migrations are intended to automate the job for applying database changes during development, meaning that your models will be always updated. As so, IMHO, you should not use models during migrations and use queries instead.

@jonlambert
Copy link
Author

Absolutely, agreed. However, what I'm looking to do is add a relationship in the same way as the models do - with foreign keys etc. There is no documentation on how to re-create the database structure generated by the Models API in a migration.

@cusspvz
Copy link

cusspvz commented Jun 26, 2015

Which SQL dialect/system are you using?

Anyway, you could debug some piece of your code that uses sequelize (trough logging option) and replicate it on a migration.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants