I have a Django 1.11.10 project with an unmanaged model like:
class MyModel(models.Model):
id = models.PositiveIntegerField(primary_key=True)
name = models.CharField(max_length=500)
class Meta:
managed = False
The model wraps a custom SQL view. However, when I run manage.py makemigrations
, I find that Django tries to generate a migration that creates a traditional SQL table for this model.
In past versions of Django, as this question illustrates, managed = False
used to prevent this. Is this no longer true? How do you get Django to not ignore schema changes on a model?
Inside the migrations file you can see options More infos can be found here)
options={
'managed': False,
},
that mean do not create a table, and as @soon say you can look on sqlmigrate
, and something like this
$ ./manage.py sqlmigrate YOUR_APP_NAME MIGRATION_NUMBER
BEGIN;
--
-- Create model MyModel
--
COMMIT
No real table created, but django need the migration to control changes of the model.
To exclude collisions, while Django do migrations it get model description not from current model files, but restore it step by step from files inside the migrtaions folder.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With