'Creating MySQL views with id to work with Django

How do I either add an auto-incremented id column to the view and/or tell Django not to look for the 'id' field?

I have a mysql view that I wish to define as a self-managed Django model

managed = False

I don't have an id column because I am doing multiple joins and the resulting view has more rows than any of the joined tables.

I get a 1054 error When I try to access the model

myview.objects.all()
OperationalError: (1054, "Unknown column 'myview.id' in 'field list'")

Answer: The best I have found so far is something like:

CREATE OR REPLACE VIEW myview AS
SELECT ROW_NUMBER() over (ORDER BY <field>) as id, ...


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source