whole description of model.py file with example.
In this Django tutorial, we are going to learn how to create a database in Django. When we created our project Django included a file called settings.py. In this file, there is some basic configuration information that allows us to use SQLite database. Also in the setting.py file there is some included apps that ship with Django that allow us to do some cool things with Django but before we can use these apps we need a database to be created to allow us to store data.
How To Create A Database in Django
Now the database that we will be creating is just for development purposes so do not go and enter a ton of data with hopes it will deploy with you project when we go live. The SQLite server is a basic database not designed to handle everyday use but is great for development purposes. SQLite is easy to work with and is light enough that it should not slow down your computer.
Now let's create that SQLite database. To create the database we run a simple command via the terminal that migrates data from Django project into a database. This command makes working with databases a breeze in Django.
First we need to be in the file that contains manage.py. If you are still the same location from the previous type cd ../ and then enter. Then type ls then enter you should see the manage.py file. Now that you have access to manage.py we can now run the command that will migrate the database. Type python manage.py migrate this will create the database.
(lpt) Thomass-MBP:lpt Tommy$ cd ../
(lpt) Thomass-MBP:lpt Tommy$ ls
lpt manage.py
(lpt) Thomass-MBP:lpt Tommy$ python manage.py migrate
Operations to perform:
Apply all migrations: sessions, auth, contenttypes, admin
Running migrations:
Rendering model states... DONE
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying admin.0002_logentry_remove_auto_add... OK
Applying contenttypes.0002_remove_content_type_name... OK
Applying auth.0002_alter_permission_name_max_length... OK
Applying auth.0003_alter_user_email_max_length... OK
Applying auth.0004_alter_user_username_opts... OK
Applying auth.0005_alter_user_last_login_null... OK
Applying auth.0006_require_contenttypes_0002... OK
Applying auth.0007_alter_validators_add_error_messages... OK
Applying sessions.0001_initial... OK
As you can see the migrate command create a database and all the required tables in the database for our Django project.
Conclusion
In this tutorial we learned how to create a database in Django. If you have any questions or issues please leave a comment below and we will do our best to help you out.