Answers for "django models for existing database"

0

django models for existing database

#Auto-generate the models
python manage.py inspectdb
#Save this as a file by using standard Unix output redirection:
python manage.py inspectdb > models.py
#By default, inspectdb creates unmanaged models. That is, managed = False in the model’s Meta class tells Django not to manage each table’s creation, modification, and deletion:
class Person(models.Model):
    id = models.IntegerField(primary_key=True)
    first_name = models.CharField(max_length=70)
    class Meta:
       managed = False
       db_table = 'CENSUS_PERSONS'
Posted by: Guest on August-24-2021
0

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'
    }
}
Posted by: Guest on August-05-2020

Python Answers by Framework

Browse Popular Code Answers by Language