I have an existing Table in Mysql database. I want to retrieve the values from the table and show them in grid using a Template.
-
1What did you try so far and what exact difficulties do you encounter?Renaud Pacalet– Renaud Pacalet2015-09-14 06:44:04 +00:00Commented Sep 14, 2015 at 6:44
-
you can check this docs.djangoproject.com/en/dev/howto/legacy-databasessalmanwahed– salmanwahed2015-09-14 06:59:00 +00:00Commented Sep 14, 2015 at 6:59
Add a comment
|
1 Answer
In your settings assigning the values in DATABASES variable.
DATABASES = {
# after your 'default' connection:
'legacy_db': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'old_db',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
Auto generate the django models using inspectdb
$ python manage.py inspectdb > /your_app/models.pyIt will generate models your existing Table.
note: If you use the MyISAM storage engine please be aware of foreign-key constraints. django detects fk fields on InnoDB engine only.
- Retrieve your data from existing MySQL tables using multiple-databases
get your objects selecting-a-database
>>> # This will run on the 'legacy_db' database.
>>> Foo.objects.using('legacy_db').all()