Create Models in Django
Models in django
A model is a class that represents a table in our database. Every attribute of the class is a field of the table. Models are defined in the directory : appname/models.py. In our example : accounts/models.py.
Open the models.py and create a class with the name of the table you want to create in the database and add the fields in that class as shown below:
Now run the following command to create the migration:
You will get the migrations in the appname/migrations folders.
Open the migration file and you will be able to see all the fields you had created in the models.
Now you have to register the model in the admin.py.
Open the admin.py file and add the below code:
Now migrate the table using the following command :
Now you can check your database. The table and the table structure will be visible there.
You can see the newly created table in the admin panel under the appname heading(accounts) by going to the below given url in your browser:
http://localhost:8000/admin/
Tags: Funda of web it Django tutorials, Django tutorials, Django tutorials funda, django for beginners, how to make migrations in django, django models, how to make models in django, make models and migrations in django, how to make migrations and models in django