Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Migrations | Models
Django: First Dive
course content

Conteúdo do Curso

Django: First Dive

Django: First Dive

1. Get Started
2. Write the First Page
3. Models
4. Working with Database
5. Templates
6. Request Handling

Migrations

The Python code is independent of the database.

To apply changes in our database, we need to create migrations.

Migration is the automated way of making changes to your database structure, ensuring that your database stays up to changes you make to your code.

When you create the Model class, you need to run the following commands in the Terminal:

makemigrations

The python manage.py makemigrations command records the changes in the database and creates migrations.

Migrations are represented as Python files (.py format).

These files contain scripts and data for migration and database structure changes.

Note

This is the process of the framework. Migrations work automatically. You do not need to touch these files. Only sometimes, there are moments when it is desirable to delete the migration and create a new one, but this is only a last resort.

migrate

To apply created migrations, you need to run another command in the Terminal.
The command python manage.py migrate executes migrations scripts (.py files) and sends queries to the database.

Note

When you move the Django to another device, you can run the migrate command only because the migrations are already saved in files.

1. How to create migration files?
2. How to apply migrations?
question-icon

How to create migration files?

Clique ou arraste solte itens e preencha os espaços

question-icon

How to apply migrations?

Clique ou arraste solte itens e preencha os espaços

Tudo estava claro?

Seção 3. Capítulo 4
We're sorry to hear that something went wrong. What happened?
some-alt