A model is the single, definitive source of information about your data.
It contains the essential fields and behaviors of the data you’re storing.
Generally, each model maps to a single database table.
Model class is a class which will represent a table in database.
Each model is a Python class that subclasses django.db.models.Model
Each attribute of the model represents a database field.
With all of this, Django gives you an automatically-generated database - access API Django provides built-in database by default that is sqlite
database.
We can use other database like MySQL, Oracle SQL etc.
.png?h=4592db18b9f4dbb7e1060f7196e076b8)
Field Name instantiated as a class attribute and represents a particular table’s Column name.
Field Type is also known as Data Type.
A field name cannot be a Python reserved word, because that would result in a Python syntax error.
A field name cannot contain more than one underscore in a row, due to the way Django’s query lookup syntax works.
A field name cannot end with an underscore.
Once you have defined your models, you need to tell Django you’re going to use those models.
Open settings.py file
Write app name which contains models.py file in INSTALLED_APPS = [ ]
Open Terminal
Run python manage.py makemigrations
Run python manage.py migrate
Migrations are Django’s way of propagating changes you make to your models (adding afield, deleting a model, etc.) into your database schema.
makemigrations – This is responsible for creating new migrations based on the changes you have made to your models.
migrate – This is responsible for applying and unapplying migrations.
sqlmigrate – This displays the SQL statements for a migration.
showmigrations – This lists a project’s migrations and their status.
.png?h=191f71b0de9769ef9498f2ed377e6cc3)
.png?h=34af95ebe5b0e2441aaba94473e83c47)
.png?h=2a11ae5b3cc6d01ae5cfcb7f04102da5)
.png?h=db1c07d9cdf12d9a1db8151d25324b67)
.png?h=c2c146ccd5092aed054e5e80ee9869cf)
.png?h=b2bfcdd8d2e47c8803e15a46e0f5c78b)
.png?h=5daeb31a2cf9831d30e2fe61dc9b0a14)
.png?h=dbf5a1eb929eea9aff872fa855ec929a)
.png?h=61df33fe0a017dde94842e48b9fe5d1a)
.png?h=9268eb10c32bbc7075dd2431ce440ff9)
.png?h=a2d576be55cd6a2f67d8361c09e41fd4)
.png?h=f2caad20a9cb68898dbe09ff2eab7a50)
.png?h=89d83059d94fa27462c20756d99319c4)
.png?h=a30b03258188c23dd1cec9e91afdd789)
.png?h=0f14434403c6b99239cb99184c19c993)
.png?h=d393e98f6f37a4635b756887435aeafe)
.png?h=fcb9ecbef48f52643ddd48ee56cc5a2f)