此问题在此处已有答案:
OperationalError, no such column. Django(30个答案)
9小时前关门了。
嘿,伙计们,我的工作与django框架,我有错误OperationalError
.
我有两个具有相同字段的类:
class Student(models.Model):
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
id = models.AutoField(primary_key=True)
First_Name = models.CharField('First Name', max_length=30, null=True, blank=True)
Last_Name = models.CharField('Last Name', max_length=30, null=True, blank=True)
ID_Number = models.CharField('Id Number', max_length=30, null=True, blank=True)
Phone = PhoneNumberField('Phone',null=True)
class Meta:
verbose_name_plural = "Students"
def __str__(self):
return str(self.user)
class Lecturer(models.Model):
user = models.OneToOneField(User, null=True, blank=True, on_delete=models.CASCADE)
id = models.AutoField(primary_key=True)
First_Name = models.CharField('First Name', max_length=30, null=True, blank=True)
Last_Name = models.CharField('Last Name', max_length=30, null=True, blank=True)
ID_Number = models.CharField('Id Number', max_length=30, null=True, blank=True)
Phone = PhoneNumberField('Phone',null=True)
class Meta:
verbose_name_plural = "Lecturers"
def __str__(self):
return str(self.user)
我为Student和Lecturer类添加了一个新字段,该字段为
Phone = PhoneNumberField('Phone',null=True)
是的,我做了命令:
python manage.py makemigrations
python manage.py migrate
在那之后我确信一切都更新了:
Operations to perform:
Apply all migrations: HomePage, accounts, admin, auth, contenttypes, sessions
Running migrations:
No migrations to apply.
但是当我运行 runserver 时,我会转到管理路径:
访问
添加我去讲师数据一切工作都很好我有新的领域电话:
但是,当我尝试转到学生数据时,我收到一个错误,无法识别字段的电话!
1条答案
按热度按时间qhhrdooz1#
如果不想丢失
db.sqlite3
,请尝试先删除迁移步骤1:删除
db.sqlite3
文件。步骤2:
$ python manage.py migrate
步骤3:
$ python manage.py makemigrations
步骤4:使用
$ python manage.py createsuperuser
创建超级用户将自动生成新的
db.sqlite3
。Take a look at this entry