Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#16303 closed Uncategorized (invalid)

How do I test a database view

Reported by: benedict.m.holland@… Owned by: nobody
Component: Testing framework Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I have a database which has views in it. I need to run tests against this, so I created unmanaged models. Now I run tests and I get the error:

DETAIL: Table X references Y
HINT: Truncate table Z at the same time, or use TRUNCATE ... CASCADE.

which is basically caused by the fact that foreign keys are based off of the view. I get this when the TRUNCATE statement is run between tests. What worked was when I went into the DB and ran the same statement as a TRUNCATE CASCADE, but I can't figure out where this truncate statement is run from the django side.

Another possible fix is the use of essentially #IFDEF statements in c, but I don't know if any variable is defined for django when it is running tests. I also don't honestly know why the TRUNCATE isn't a CASCADE since all of the data is destroyed between tests anyway. Is there a known work around for this?

Thanks so much

Change History (2)

comment:1 Changed 8 years ago by Aymeric Augustin

Resolution: invalid
Status: newclosed

Trac is not the place to ask "how do I" questions — it is a database of known bugs in Django.

If you want help debugging your problem, please ask on the django-users mailing list, or on #django in IRC.

comment:2 Changed 8 years ago by anonymous

That is fine, but I am getting an error running tests, doing something that is fairly normal procedure. Also I am not sure if it is a bug or not where TRUNCATE does not call a CASCADE. I actually found the file, added CASCADE and the error goes away. It is located at:


Note: See TracTickets for help on using tickets.
Back to Top