django models for existing database

Solutions on MaxInterview for django models for existing database by the best coders in the world

showing results for - "django models for existing database"
Isidora
22 Feb 2016
1#Auto-generate the models
2python manage.py inspectdb
3#Save this as a file by using standard Unix output redirection:
4python manage.py inspectdb > models.py
5#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:
6class Person(models.Model):
7    id = models.IntegerField(primary_key=True)
8    first_name = models.CharField(max_length=70)
9    class Meta:
10       managed = False
11       db_table = 'CENSUS_PERSONS'
Alessandra
09 May 2019
1DATABASES = {
2    'default': {},
3    'users': {
4        'NAME': 'user_data',
5        'ENGINE': 'django.db.backends.mysql',
6        'USER': 'mysql_user',
7        'PASSWORD': 'superS3cret'
8    },
9    'customers': {
10        'NAME': 'customer_data',
11        'ENGINE': 'django.db.backends.mysql',
12        'USER': 'mysql_cust',
13        'PASSWORD': 'veryPriv@ate'
14    }
15}
16