0

I am moving my web application from rails to django, I have successfully connected to my PostgreSQL DB with the django application. My question is, do I have to recreate all of the rails models in django (which will create new database tables) or is there a way to use the existing tables as they are? I am looking through documentation but have not found the specific answer I am looking for.

1

1 Answer 1

1

You can say to django that you don't want your table to be created by adding a managed attribute to False on your models Meta.

class MyModel(models.Model):
    class Meta:
        managed = False

The classes for the models can be created with the inspectdb management command. This command will set the managed attribute to False.

I suggest that you create this model file, remove the managed attribute, et create an initial migrations. You will then manually insert the row for this initial migration on your production database (django_migrations table if I remember correctly) to tell Django that all those tables have already been created.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you recommend doing things in the order you provided? If I remove the managed attribute and run initial migrations before I manually enter the row into django_migrations, will it try to create the tables again?
It should try to create the tables, but I think it would fail since they already exists. I would generate the models, remove the managed attribute, and create the initial migration. Then, before pushing to production, I would add the initial migration to the DB.

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.