Comments (8)
After more experience with Sequelize and another ORMs I understand a lot of things in development and deploying projects.
This is not issue, it is absolutely normal - defining structure in model and create few migrations for updating database structure through time.
I think current issue may be closed.
from express-example.
@webman I may be a little off with the answer, but here it goes.
The model is used to represent the table as an object.
A migration is used to transition the database state, so if you add or remove something from your model you can run a migration and it will update the database. You can also undo migrations to return to a previous state, so say you needed to undo the change you made you could undo that migration and return to the previous instance of your database state.
Does this make sense or help?
from express-example.
@kjloveless In other frameworks (such as Express, Adonis, Laravel) we not need to define structure twice. Usually done only migration (DB schema), but in model file dont specify structure. And this is comfortable for development - structure defined in one file.
from express-example.
@webman I'm not sure I follow exactly what you're trying to get at honestly... You can think of the model as the object that you are going to get back from your database and the migration is simply a log of changes applied to your database. So you're really defining the structure of a table with the migration and of an object with the model... Does that make sense?
[https://laracasts.com/discuss/channels/laravel/the-difference-between-a-model-and-a-migration](Maybe this link will help?)
I do think it would be nice however if the migration files would be able to be generated based off the corresponding model file, but people has made additional libraries to solve this as well already. This would probably get rid of your feeling of defining things twice..
In summary, they're two separate thing...
@sushantdhiman can you confirm my answer? or clear things up for Webman if I misspoke?
from express-example.
I advocate this example repository being explicit in showing migration structure, but perhaps it could also give an example of how to skip the migrations and use sync.
from express-example.
Another thing to consider is that generating a model with --attributes
allows you to define the structure once, generating the model and migration. Edits would then require defining the same information twice though.
from express-example.
Tracking issue for this is basically here: sequelize/sequelize#5213
from express-example.
Hi everyone, thanks for raising this issue, sorry to take so long to give you more attention. I believe this is a common question, I will try to improve the docs on this at some time, but a short answer is as follows.
Models are the main thing. The feature of migrations exist for version-controlling the state of your database; migrations are not mandatory. One can start to use migrations long after the database is already running, even in production. The duplicated structure that could be seen in the old example was caused by the decision of applying migrations since the very beginning, representing the state change from 'database does not even exist' to 'now database exists with these tables'. In my opinion, this is not very useful. What I would recommend is to just set up the database without migrations, and start using migrations only after your service is already running in production and you have to change something.
Feel free to ask me any further questions 😁
from express-example.
Related Issues (20)
- I'm receiving a ERROR: sequelize is not defined HOT 2
- How to use the transaction? HOT 1
- Add TypeScript Example HOT 2
- Add examples of associations HOT 1
- nodemon index.js doesn't work
- upsert route HOT 1
- Should the directory structure be updated to adapt to the directory structure of Sequelize CLI?
- Contributing and Maintaining information HOT 2
- dynamic imports do not work for defining models HOT 2
- "node_modules/.bin/sequelize" is not work on windows HOT 2
- Unit test hanging or sequelize doesn't close connection HOT 1
- enable Travis CI / Circle CI
- how to use DataType from req.body HOT 2
- npm install error HOT 4
- duplicate foreignKey when using sequelize.sync() HOT 3
- What does Model.associate() do in model/index.js ? HOT 4
- Please provide an example using sequelize v5 and TypeScript. HOT 6
- Update this repo HOT 3
- Stop using `sequelize.import` HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from express-example.