Is it possible to migrate a web2py system to Django by maintaining the same database?

Asked

Viewed 64 times

0


It is possible to migrate a web system in production made in web2py to a redone in Django, maintaining the same database?

I have a system made in web2py (in production) and need to redo it in Django, keeping the same database. The problem is that Django and web2py have different tables systems for users.
Therefore, the database in production has the web2py user tables, while in Django several tables are created by default (being the user only one of them).
How I can make Django work (with authentication system) using a ready-made database of a web2py system?
Thank you for your attention!


P.S.: the original BD was made in postgresql.

  • I don’t know Web2py and I don’t know which table structure was created for authentication. Maybe if you put a schema print it might be easier to point out a solution.

1 answer

0

Django has a tool called inspectdb which can create the templates by entering the existing database. You can check the output by running this command:

$ python manage.py inspectdb

Save it as a file:

$ python manage.py inspectdb > models.py

Once you’ve cleaned your templates, name a file models.py and put it in the Python package that contains your application. Then add the app within your INSTALLED_APPS definition.

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'

Then perform the appropriate migrations:

$ python manage.py migrate

In addition, you can manually map the bank on models.py, generate a JSON your legacy bank and finally use the command loaddata to charge your bank in Django:

$ django-admin loaddata mydata.json

see more about loaddata and also dumpdata here.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.