0

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.

2

1 Answer 1

5

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.py
    

    It 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.

get your objects selecting-a-database

>>> # This will run on the 'legacy_db' database.
>>> Foo.objects.using('legacy_db').all()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.