Python Django:没有此类列的操作错误
我对数据库(我对它们一无所知)和Django非常陌生,尽管我对Python很了解。我正在使用Sqlite作为我的数据库软件。我不断地得到一份工作Python Django:没有此类列的操作错误,python,django,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
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\u id,当我创建表时,它没有显示任何名为user\u id的列。有人能帮我纠正一下吗?手动删除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
您的表没有该列。一般建议:使用south迁移数据库,以便每次向数据库添加新列时都会添加新列。非常感谢。我也有类似的问题。我正在做makemigration,它问了我两个我没有得到的选项。我得到以下信息。我如何进一步进行?您正在尝试添加一个不可为空的字段“user”,我们无法这样做(数据库需要一些东西来选择修复程序:1)立即提供一个一次性默认值(将设置为2)退出,让我在模型中添加一个默认值。选择一个选项:在没有默认值的情况下发布;填充现有行)。(所有现有行)