Designing Profile Model
Now we are going to learn how to design the models and how it impacts on DB?
1) Open the models.py and develop the code as below
2)Now make the migration ready
>python .\manage.py makemigrations
>python .\manage.py migrate
and then run the python server
>python .\manage.py runserver
3)Once migration is successful then verify into your respective DB.
For me, Let's verify it into MongoDB.
Just start your MongoDB servers and open DB GUI(MongoDB Compass)
Note:
There are several commands which you will use to interact with migrations and Django’s handling of database schema:
- migrate: which is responsible for applying and unapplying migrations.
- makemigrations: This is responsible for creating new migrations based on the changes you have made to your models.
- sqlmigrate: which displays the SQL statements for a migration.
- showmigrations: which lists a project’s migrations and their status.
One of the best features of Django is that we can manage our custom models using builtin and predefined functionalities using the Django admin page.
Then what we need to do so?
As simple as that, we need to register this model into the Django admin app.
1)Just open admin.py and develop the below piece of code.
>python .\manage.py makemigrations
>python .\manage.py migrate
and then run the python server
>python .\manage.py runserver
and login into the Django admin page and observer the changes.
http://127.0.0.1:8000/admin