我正在尝试创建一个彩票应用程序,它一直工作正常,但今天当我尝试做一个python manage.py迁移lotteryapp它开始产生一个错误,说明
django.db.utils.OperationalError: (1060, "Duplicate column name 'email'")
所以我删除了所有电子邮件的引用,看看是否会修复它,但它仍然会出错。然后,我一起删除了数据库并重新启动,但随后又出现了此错误
ValueError: invalid literal for int() with base 10: ''
我已经进入了我的models.py文件并返回并再次运行该命令,它再次给出了重复的列错误。它没有任何意义。这是来自models.py的代码:
from django.db import models
from django.utils import timezone
from datetime import datetime
class Lottery(models.Model):
name = models.CharField(default="", max_length=50)
date_drawn = models.DateTimeField(default=datetime.now,blank=True)
win_amount = models.IntegerField(default=0)
winning_numbers = models.IntegerField(default="")
def __unicode__(self):
return self.name
class Winner(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
winner_telephone = models.IntegerField(max_length=15, default="")
lottery_numbers = models.IntegerField(default=0)
lottery_won = models.CharField(max_length=50, default="")
def __unicode__(self):
return self.name
class User(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
telephone = models.IntegerField(default="")
def __unicode__(self):
return self.first_name
class entered_user(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
telephone = models.IntegerField(default="")
lottery_numbers = models.IntegerField(default="")
def __unicode__(self):
return self.first_name
答案 0 :(得分:1)
问题在于字段lottery_won
和lottery_numbers
。将默认值更改为0,然后重试。
答案 1 :(得分:0)
IntegerField不能包含默认字符串类型,也没有 max_length 属性:
避免调用您的模型用户,因为它可能会导致与默认的django 用户模型冲突,这可能是电子邮件错误消息的原因。
@CNB 我尝试了以下代码我刚刚将用户更改为 UserModel ,迁移工作正常:
from __future__ import unicode_literals
from django.db import models
from django.db import models
from django.utils import timezone
from datetime import datetime
class Lottery(models.Model):
name = models.CharField(default="", max_length=50)
date_drawn = models.DateTimeField(default=datetime.now,blank=True)
win_amount = models.IntegerField(default=0)
winning_numbers = models.IntegerField(default=0)
def __unicode__(self):
return self.name
class Winner(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
winner_telephone = models.IntegerField(default="")
lottery_numbers = models.IntegerField(default=0)
lottery_won = models.CharField(max_length=50, default="")
def __unicode__(self):
return self.name
class UserModel(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
telephone = models.IntegerField(default=0)
def __unicode__(self):
return self.first_name
class entered_user(models.Model):
first_name = models.CharField(max_length=100, default="")
last_name = models.CharField(max_length=100, default="")
telephone = models.IntegerField(default=0)
lottery_numbers = models.IntegerField(default=0)
def __unicode__(self):
return self.first_name