django admin error - Unknown column 'django_content_type.name' in 'field list'

后端 未结 7 942
广开言路
广开言路 2021-01-17 15:35

My django project had a working admin page, but all of the sudden I started receiving: \"Unknown column \'django_content_type.name\' in \'field list\'\" whenev

7条回答
  •  孤城傲影
    2021-01-17 15:57

    The fix in MySQL for us was to drop table django_content_type;

    The notes from karthikr and moonchel led me to the fix. 1054 Unknown column errors were occurring after installing Django 1.8 into one virtualenv to try it out, and then trying to use the pre-existing Django 1.6 in a different virtualenv. MySQL got messed up.

    Django 1.7/1.8 syncdb revised the django_content_type table removing the 'name' column from it.

    +-----------+--------------+------+-----+---------+----------------+
    | Field     | Type         | Null | Key | Default | Extra          |
    +-----------+--------------+------+-----+---------+----------------+
    | id        | int(11)      | NO   | PRI | NULL    | auto_increment |
    | app_label | varchar(100) | NO   | MUL | NULL    |                |
    | model     | varchar(100) | NO   |     | NULL    |                |
    +-----------+--------------+------+-----+---------+----------------+
    
    Django 1.6 syncdb creates the table with the 'name' column:
    +-----------+--------------+------+-----+---------+----------------+
    | Field     | Type         | Null | Key | Default | Extra          |
    +-----------+--------------+------+-----+---------+----------------+
    | id        | int(11)      | NO   | PRI | NULL    | auto_increment |
    | name      | varchar(100) | NO   |     | NULL    |                |
    | app_label | varchar(100) | NO   | MUL | NULL    |                |
    | model     | varchar(100) | NO   |     | NULL    |                |
    +-----------+--------------+------+-----+---------+----------------+
    

    So drop the table and let syncdb recreate it as required for the Django version. Take a dump if nervous about dropping it: mysqldump -u -p django_content_type > /tmp/django_content_type.dmp

提交回复
热议问题