0 votes
in Python by
Give a detailed explanation about setting up the database in Django.

1 Answer

0 votes
by

The process of setting up a database is initiated by using the command edit mysite/setting.py. This is a normal Python module with a module-level representation of Django settings. Django relies on SQLite by default, which is easy to be used as it doesn’t require any other installation.

SQLite stores data as a single file in the filesystem. Now, you need to tell Django how to use the database. For this, the project’s setting.py file needs to be used. Following code must be added to the file for making the database workable with the Django project:

DATABASES = {

 'default': {

 'ENGINE' : 'django.db.backends.sqlite3',

 'NAME' : os.path.join(BASE_DIR, 'db.sqlite3'),

 }

}

If you need to use a database server other than the SQLite, such as MS SQL, MySQL, and PostgreSQL, then you need to use the database’s administration tools to create a brand new database for your Django project.

You have to modify the following keys in the DATABASE ‘default’ item to make the new database work with the Django project:

ENGINE – For example, when working with a MySQL database replace ‘django.db.backends.sqlite3’ with ‘django.db.backends.mysql’

NAME – Whether using SQLite or some other database management system, the database is typically a file on the system. The NAME should contain the full path to the file, including the name of that particular file.

NOTE: - Settings like Host, Password, and User needs to be added when not choosing SQLite as the database.

Related questions

0 votes
asked Aug 29, 2020 in Python by Robindeniel
+1 vote
asked May 23, 2020 in Python by sharadyadav1986
...