Django中CalendarEvents模型对应数据库表无法创建求助
Django项目中CalendarEvents模型数据库表创建失败问题
我有一个包含多个子应用的Django项目,其中calendar_event应用的models.py定义了CalendarEvents模型。多次尝试创建该模型对应的数据库表均失败,即便尝试重置数据库、重置迁移、使用--fake和zero参数处理迁移等多种方案都无效。执行makemigrations时显示该表已准备创建,但migrate后数据库中始终不存在该表,其他应用的表均正常创建。showmigrations显示calendar_event的迁移已标记为应用,但通过Django Shell查询该模型时提示表不存在,数据库shell及PGAdmin中也无此表,且该应用已添加至settings.py的INSTALLED_APPS中。
模型代码
class CalendarEvents(models.Model): id = models.AutoField(primary_key=True) type = models.CharField(max_length=50, choices=EVENT_CHOICES, null=True, blank=True) name = models.CharField(max_length=145,null=True, blank=True) description = models.TextField(null=True, blank=True) location = models.CharField(max_length=100, null=True, blank=True) creator = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE, related_name='creator') guests = models.ManyToManyField(settings.AUTH_USER_MODEL, null=True, blank=True) start = models.DateTimeField(null=True, blank=True) end = models.DateTimeField(null=True, blank=True) event_last_date = models.DateField(null=True, blank=True) repeating = models.BooleanField(default=False, null=True, blank=True) repeat_interval = models.IntegerField(null=True, blank=True) repeat_frequency = models.CharField(max_length=20, choices= RECURRENCE_CHOICES, null=True, blank=True) repeat_by_weekdays = ArrayField(models.IntegerField(choices=WEEKDAY_CHOICES), default=list, null=True, blank=True) recurrence = RecurrenceField(null=True, blank=True, verbose_name="Recurrence")
已尝试的解决方案
- 重置所有迁移(保留
__init__.py文件) - 重置数据库并重新创建
- 使用
--fake和zero参数从初始状态迁移
内容的提问来源于stack exchange,提问作者Langutang
相关产品推荐
相关产品推荐

