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 impression that Django won't generate a migration for a model if it has the managed = False
option. However, it's still trying to create it.
Also, I'm using Django 1.8 with Python 3.4.
I'm having trouble creating a Django model for a Postgres view, using these links as a guide: drdaeman and eceppda's answer in Can I use a database view as a model in django. I also looked up the Options.managed entry in Django's API docs. However, even with this, it's creating a migration that adds a table for the view's model.
This is my code so far:
foo/models.py
class RelevantModel(models.Model):
rebate_pool_total = models.OneToOneField('foo.VirtualTotal', null=True)
total = models.DecimalField(null=True, decimal_places=2, max_digits=32)
class VirtualTotal(models.Model):
relevant_model = models.ForeignKey('foo.RelevantModel')
total = models.DecimalField(null=True, decimal_places=2, max_digits=32)
class Meta:
managed = False
foo/migrations/0009_add_foo_view.py
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('foo', '0008_previous_migration'),
]
sql = """
create VIEW foo_virtualtotal AS
SELECT rest of view...
"""
operations = [
migrations.RunSQL('DROP VIEW IF EXISTS foo_virtualtotal;'),
migrations.RunSQL(sql)
]
What am I doing wrong?