How to Configure Database in Django.

devquora
devquora

Posted On: Feb 22, 2020

 

    1 Answer Written

  •  devquora
    Answered by Shashank Garg

    In Django database can be configured by setting the 'DATABASES' constant in settings.py file. For example:

    If you want to configure and use SQLite as the default database then.

    DATABASES = {
            'default': {
                            'ENGINE': 'django.db.backends.sqlite3',
    			'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
    		       }
    	     }
    

    or in order to define multiple databases in Django use the below configuration.

           DATABASES = {'default': {
    				'ENGINE': 'django.db.backends.sqlite3',
    				'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),   
    				 },
    				 'mysql': {
    				          'ENGINE': 'django.db.backends.mysql',
    					  'NAME': 'DbName',       
    					  'USER': 'User',       
    					  'PASSWORD': 'password',       
    					  'HOST': 'db',          
    					  'PORT': '3306',   
    					 }
    				   }
    

Related Questions

Please Login or Register to leave a response.

Related Questions

Django Interview Questions

What does Of Django Field Class types do?

What does Of Django Field Class types do?..

Django Interview Questions

Does Django Follow Architectural pattern?

Does Django Follow Architectural pattern?..