Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Edit database outside Django ORM

If one is using Django, what happens with changes made directly to the database (in my case postgres) through either pgadmin or psql?

How are such changes handled by migrations? Do they take precedence over what the ORM thinks the state of affairs is, or does Django override them and impose it's own sense of change history?

Finally, how are any of these issues effected, or avoided, by git, if at all?

Thanks.

like image 277
Malik A. Rumi Avatar asked Feb 08 '16 15:02

Malik A. Rumi


1 Answers

You can exclude a model completely from the django migrations, and then you are responsible to adjust the schema to the django code (or the django code to the existing schema):

class SomeModel(models.Model):

    class Meta:
        managed = False  
        db_table = "some_table_name"   

    name = models.Fields....

Note that you can't have it both ways, so migrations are preferred when possible. You can always define a custom SQL migration, that will save the need for external changes. However, sometimes you do need to handle the schema elsewhere instead of migrations, and then use managed=False

like image 96
Aviah Laor Avatar answered Sep 18 '22 11:09

Aviah Laor