create database django code example
Example 1: database setup in django
sudo apt install python3-dev libmysqlclient-dev default-libmysqlclient-dev
Example 2: django creating database
In your virtual environment, where your Django project lives,
use the following commands:
>> python3 manage.py makemigrations
>> python3 manage.py migrate
>> python3 manage.py sqlmigrate "name_app" "code_of_specific_object"
>> python3 manage.py shell
Example 3: use django with another database
DATABASES = {
'default': {},
'users': {
'NAME': 'user_data',
'ENGINE': 'django.db.backends.mysql',
'USER': 'mysql_user',
'PASSWORD': 'superS3cret'
},
'customers': {
'NAME': 'customer_data',
'ENGINE': 'django.db.backends.mysql',
'USER': 'mysql_cust',
'PASSWORD': 'veryPriv@ate'
}
}
Example 4: how to store the database in the django
>>> Person.objects.raw('''SELECT first AS first_name,
... last AS last_name,
... bd AS birth_date,
... pk AS id,
... FROM some_other_table''')