我正在尝试开发一个web应用程序,提供在django上创建一个迷你游戏联盟。在创建数据库时,我得到以下错误:
You are trying to add a non-nullable field 'id' to juego without a default; we can't do that (the database needs something to populate existing rows).
这是我在文件models.py
上的类Juego
:
class Juego(models.Model):
nombre_juego = models.CharField(max_length=100)
record = models.DecimalField(max_digits=10000000, decimal_places=3)
fecha_inicio = models.DateTimeField(default=timezone.now)
fecha_fin = models.DateTimeField(default=timezone.now)
enlace = models.CharField(max_length=1000)
在上次迁移之后,我将以下类添加到模型中:
^{pr2}$
你现在的代码没有问题。我刚做了一个django项目并运行了它:
型号:
迁移1:
^{pr2}$迁移2:
运行这个:
问题一定是在你展示的片段之外的某个地方:可能是数据完整性问题。如果你还没有任何重要的数据,你应该考虑重新建立一个新的数据库。在
相关问题 更多 >
编程相关推荐