title: Django model for a Postgres view
body: <p><strong>Edit:</strong> There seems to be some confusion about what I'm asking. That model is for the <a href="https://www.postgresql.org/docs/9.4/static/sql-createview.html" rel="noreferrer">Postgres view</a> 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 <code>managed = False</code> option. However, it's still trying to create it.</p>
  
  <p>Also, I'm using Django 1.8 with Python 3.4.</p>
  
  <p>I'm having trouble creating a Django model for a Postgres view, using these links as a guide: <a href="https://stackoverflow.com/a/1281051/2258441">drdaeman</a> and <a href="https://stackoverflow.com/a/29532034/2258441">eceppda's</a> answer in <a href="https://stackoverflow.com/questions/507795/can-i-use-a-database-view-as-a-model-in-django">Can I use a database view as a model in django</a>. I also looked up the Options.managed entry in <a href="https://docs.djangoproject.com/en/1.8/ref/models/options/#django.db.models.Options.managed" rel="noreferrer">Django's API docs</a>. However, even with this, it's creating a migration that adds a table for the view's model.</p>
  
  <p>This is my code so far:</p>
  
  <h3>foo/models.py</h3>
  
  <pre><code>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
  </code></pre>
  
  <h3>foo/migrations/0009_add_foo_view.py</h3>
  
  <pre><code># -*- 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)
      ]
  </code></pre>
  
  <p>What am I doing wrong? </p>