Django:没有这样的列的OperationalError

时间:2014-04-08 11:47:19

标签: python django

我对数据库(对我们一无所知)和Django都很陌生,尽管我对Python很了解。我使用Sqlite作为我的数据库软件。我一直在

OperationalError at /admin/auth/user/add/ 
table dashboard_member has no column named user_id
每次我尝试从Django管理面板添加新用户时出现

错误。这是我的models.py:

from django.db import models    # importing database library from Django   
from django.contrib.auth.models import User

class Member(models.Model):    # table for members' info

    DEPARTMENTS = (
        ('Quiz', 'Quizzing'),
        ('Design', 'Design'),
        ('Elec', 'Electronics'),
        ('Prog', 'Programming'),
    )

    CLASSES = (                 # tuples to store choices for each field
        (9, '9'),               # (actual value to be stored, human-readable value),
        (10, '10'),
        (11, '11'),
        (12, '12'),
    )

    DESIGNATIONS = (
        ('Mem', 'Member'),      
        ('ExecMem', 'Executive Member'),
        ('VicePres', 'Vice President'),
        ('Pres', 'President'),
    )

    user = models.OneToOneField(User)   # to inherit the properties of the base User class in Django, like first_name, last_name, password, username, etc.
    schoolClass = models.IntegerField('Class', choices = CLASSES)
    desig = models.CharField('Designation', max_length = 20, choices = DESIGNATIONS)
    dept1 = models.CharField('Department 1', max_length = 20, choices = DEPARTMENTS)
    dept2 = models.CharField('Department 2', max_length = 20, choices = DEPARTMENTS)
    #proPic = models.ImageField('Profile Picture', upload_to = 'profile_pics')

    def __unicode__(self):
        return self.user.username

class DepInfo(models.Model):        # table for info specific to each department

    DEPARTMENTS = (
        ('Quiz', 'Quizzing'),
        ('Design', 'Design'),
        ('Elec', 'Electronics'),
        ('Prog', 'Programming'),
    )

    dept = models.CharField('Department', max_length = 20, choices = DEPARTMENTS)
    agenda = models.TextField('Agenda', max_length = 1000)      # editable text fields
    workMat = models.TextField('Working Material', max_length = 1000)
    furRead = models.TextField('Further Reading', max_length = 1000)

这是我的admin.py:

from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.contrib.auth.admin import User

from dashboard.models import Member, DepInfo

class MemberInline(admin.StackedInline):
    model = Member
    can_delete = False
    verbose_name_plural = 'member'

class UserAdmin(UserAdmin):
    inlines = (MemberInline, )

admin.site.unregister(User)
admin.site.register(User, UserAdmin)
#admin.site.register(Member)
admin.site.register(DepInfo)

# Register your models here.

事情是,我甚至没有定义任何列user_id,当我创建表时,它没有显示任何名为user_id的列。有人可以帮我纠正一下吗?

1 个答案:

答案 0 :(得分:0)

手动删除myapp / migrations中以.py形式提供的迁移文件。这些文件的格式为: init .0001.py,0002_migrations.py。 删除所有此类类型并执行:

  

$:python manage.py makemigrations myapp

     

$:python manage.py迁移myapp 0001

     

$:python manage.py sqlmigrate myapp 0001