﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
18782	"database ""view"" treated as ""table"" on flush (mysql)"	rodolfo_3	nobody	"I'm using a mysql view (https://dev.mysql.com/doc/refman/5.0/en/create-view.html) on a Mysql database to replace a default ""auth_user_group"" table on a django project. I replace the table in a ""post_syncdb"" signal.

When I run the tests, django try to ""flush"" the database, executing a ""truncate"", it try do it with the view too. It's cause a database error, and fail the flush:

{{{
Error: Database test_yoshi couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin.py sqlflush'. That's the SQL this command wasn't able to run.
The full error: (1146, ""Table 'test_yoshi.auth_user_groups' doesn't exist"")
}}}

It's happen because the command to inspect the database on mysql backend use the command ""show tables"". But, on mysql, views are returned by this command: https://dev.mysql.com/doc/refman/5.0/en/show-tables.html

The solution is replace the query on the method ""get_table_list"" on the file ""db/backends/mysql/introspection.py"":
{{{
    def get_table_list(self, cursor):
        ""Returns a list of table names in the current database.""
        cursor.execute(""SHOW FULL TABLES WHERE TABLE_TYPE = 'BASE TABLE'"")
        return [row[0] for row in cursor.fetchall()]
}}}"	Bug	closed	Database layer (models, ORM)	dev	Normal	fixed	mysql introspection table view		Ready for checkin	1	0	0	0	0	0
