Django Configure Database Setting | Django Tutorials
August 1, 2021 2022-12-18 1:40Django Configure Database Setting | Django Tutorials
Django Configure Database Setting | Django Tutorials
Django Configure Database Setting
As you know we are publishing the Django tutorials series step by step, in today’s tutorial, you will learn all about “Django Configure Database Setting”, in which, we have discussed from basics of Databases to configure another database like MySQL, Postgres in Django project. Sure, you have understood different topics of Django but today’s lesson is very important to understand. Because without a Database you cannot build a good website or application. So lets to learn!
What is Database?
The database is the collection of logical data stored in such a way that easy to retrieve, filter, search, update or delete. Such kind of technology is linked with a website or web application or with any software to store required data. And provide data on the request of the user or admin.
Why need of Database?
The following reason, due to that we use databases for a website or web-based application to store records.
- The data store in the database is managed form
- A database can contain millions of entries of data, which makes it easy to search specific data.
- We can view all the data inside the database to display on application or website
- The millions of data can be easily controlled if our data is stored in a database
- The most important reason is that it makes easy accessibility for a website to retrieve data when required
Default Database in Django
Configuration of Database in Django
Django Configure Database Setting is very easy, but you need to know five things while configuring the database in your Django project. Those five things are mentioned below:
ENGINE: It is Django specific, it is the main and important line of code to add. This line, you get from the library which you install for a specific database, e.g MySQL or Postgres.
NAME: It is the name of the database, when you create a database, it asks you to enter your name of the database. That name you have to mention here e.g organization name, website name, etc
USER: There are different users of the database and may have different rights. You need to enter your database name for a specific database.
PASSWORD: When you give a user name, you should add to password also
PORT: It is the same number that helps to connect to that specific database properly.
Now, if you want to add a MySQL database, you need to read its requirements, for example to using MySQL you have to install a library that helps to connect with the MySQL database. Then you have to collect the above information. Then that information you will need to include in MySQL database configuration settings. (At the end of the article, I have mentioned)
Recommended to Lear:
Django Security Complete Guidelines
How to Django Configure database setting
Django support is other than sqlit3 database also like MySQL, Postgres, etc. You need to install the required Python-based libraries for that and use another database. Because sqlite3 is the light database management system which has some limitations. But you can use it with a lightweight website or application. So following, We have mentioned the Django configuration of two databases. You need to give details according to your information. I have mentioned general details.
# Django Configure database setting
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mention_database_name', 'USER': 'mention_your_usernmae_here', 'PASSWORD': 'mention_your_password_for_that_used_for_Login', 'HOST': 'name of your host, incase of locally base, write localserver', 'PORT': 'mention port numebr', } } DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'yourDBname', 'USER': 'yourOWNname_which you used for login', 'PASSWORD': 'mentionPassword_which you used for login', 'HOST': 'name of server, incase of locally, we used localserver', 'PORT': 'mention here port number', } }
Now! what you have to do?
As you have understood this article about “Django Configure Database Setting”, now you must follow instructions as discussed in this article. In case of any issues or problems, don’t worry, you can discuss them with us.
On other hand, If you have any suggestions or knowledge about this article, you can share it with us, we will appreciate you!
If this article is good then share it on Facebook, Twitter, Pinterest, Instagram, etc.
Advanced Tutorials for Beginners
Build a Django CRUD Application | Django Tutorials
What is Django Query Set API | Django Tutorial for Beginners
What are views in Django | Django Tutorials
30+ Python Web Application Projects Ideas | 100% Full Guide