Django model for a Postgres view

后端 未结 1 1331
旧巷少年郎
旧巷少年郎 2021-01-18 22:33

Edit: There seems to be some confusion about what I\'m asking. That model is for the Postgres view that I created in migration 0009. I was under the impress

1条回答
  •  孤城傲影
    2021-01-18 23:24

    Django does create a migration for each newly added table in your app regardless of whether it's a managed model or not. However there is a very important and subtle difference when you use the managed=False setting. The resultant migration is a dummy entry. It does not execute any SQL at all.

    To confirm this add a new model that is unmanaged

    class Dummy(models.Model):
        something = models.IntegerField()
    
        class Meta:
           managed = False
    

    now when you do makemigrations followed by sqlimigrate *myapp* *migration_number* you will see that it doesn't produce any sql.

    If on the other hand, you do find that Django is trying to create a table for you, that usually means that you had the same model in existence earlier but at the time the model was managed. To confirm this, search your migrations folder for VirtualTotal which is the name of the model in question.

    0 讨论(0)
提交回复
热议问题