Generally, each model maps to a single database table.We to write the field type,limits,size,etc in model.py file of the app. This will create the necessary table and fields in the database.
''' models.py '''
from django.db import models
class table_name(models.Model):
field_name= models.field_type(conditions)
Next we need to inform Django in settinggs.py
about the app which will be using this model.
''' settinggs.py ''''
INSTALLED_APPS = [
#...
'app_name',
#... ]
We are almost done. Next we need to migrate this app so that database tables are created. In terminal type the following:
python manage.py migrate
migrate
will create the necessary databases by checking the app_installed in the setting.py
By makemigrations
, Django will know the changes that are made to the models.
python manage.py makemigrations
That's it. Your database is created and you can see the schema in the terminal
python manage.py sqlmigrate app_name 0001