Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialIskander Ismagilov
13,298 PointsWhat is migration?
Is migration a process that applies all the changes which relates to models that in app or project to a database?
2 Answers
Chris Freeman
Treehouse Moderator 68,441 PointsFrom the docs, Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into.
Each model is represented by a table in the database, the table rows represents the instances and the table columns represent the model fields. as model definitions change, the database organization (or schema) must change to match. Migrations keep track of the differences at each snapshot so the database can be rolled back or forwards to match the state of the models if they are also rolled back or forward as during a checkout of different revisions from revision control.
If you are not using revision control to track your models and database schema, migrations provide an easy way to keep the database in sync with changes as they are made.
Daniel Wu
4,349 PointsWhen I run python manage.py migrate, I receive the following error message: sqlite3.operationalError: unable to open database file
how do i fix this? i think this causes problems later on in the tutorial when I can't make a migration to the courses app.
Chris Freeman
Treehouse Moderator 68,441 PointsThere are many ways this can break. Can you provide more information on what has been tried, and does work?
You can test DB connection using dbshell
$ python manage.py dbshell
Also review connecting to the database doc.
Iskander Ismagilov
13,298 PointsIskander Ismagilov
13,298 PointsGot it, thank's Chris.
Alejandro Ochoa
Courses Plus Student 10,671 PointsAlejandro Ochoa
Courses Plus Student 10,671 PointsHi Chris Freeman, would you happen to know if migrating applies or servers any kind of purpose when using a schemaless database such as mongoDB.
kerimcharyev
1,589 Pointskerimcharyev
1,589 PointsCould you please clarify difference between migrate and makemigrations??
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 Pointsmakemigrations examines the database and the models to create difference files that represent the incremental changes. The differences are stored in the migrations directory.
migrate applies the changes detected during the make process to the database to bring the database into sync.