简体   繁体   中英

django.db.utils.OperationalError: no such column: django_content_type.name?

I added a new model in models.py as:

class Attendence_Mgmt(models.Model):    
    teacher_name=models.ForeignKey(Teacher_Mgmt)
    date=models.DateField(blank=False)
    intime=models.TimeField(blank=False)
    outtime=models.TimeField(blank=False)

When i was working on my project and i run make-migrations command, it runs fine but when i run the migrate command, i suddenly encountered the above kind of error.

Why is the the above type of error occurred? How can i resolve this problem?

I think that the problem is with changing the django version. If you are upgrade your django to 1.8 but it's developed on 1.7 .... this is the problem. I'm not sure but try this: python manage.py migrate contenttypes

I have got the same problem, when trying to rollback migrations on Django 2.1.5. The migrations were generated using Django 2.0+.

I have managed to solve it by running:

$ manage.py migrate contenttypes 0001_initial
$ manage.py migrate <my_app> zero
$ manage.py migrate contenttypes
$ manage.py migrate auth

I came to this solution by listing migrations with manage.py showmigrations :

contenttypes
 [X] 0001_initial
 [X] 0002_remove_content_type_name

Since, the error message was django.db.utils.OperationalError: no such column: django_content_type.name and the second contenttypes migration explicitely removes name , I have tried to temporarily revert this migration and it worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM