我正在关注我可以到达的所有教程和参考。但是,它们都不起作用。我唯一想做的就是超级简单。我只想向构建的模型添加一列。在这种情况下,我想向Card添加一个ForeignKey。我先更改模型,然后进行迁移,然后再进行迁移。但是Django总是告诉我不适用任何迁移。为什么?
我尝试删除所有迁移文件,然后再次迁移。发生同样的事情。
这是一些模型文件。 ...
class Card(models.Model):
add_time = models.DateTimeField(auto_now_add=True)
cata = models.CharField(max_length=150,default='夹芯板')
test_cata = models.ForeignKey(Example,on_delete=models.PROTECT,null=True)
price = models.CharField(max_length=10,default='1')
noise = models.CharField(max_length=10,default='1')
flame = models.CharField(max_length=10,default='1')
moisture = models.CharField(max_length=10,default='1')
compressive = models.CharField(max_length=10,default='1')
corrosion = models.CharField(max_length=10,default='1')
shock = models.CharField(max_length=10,default='1')
thermal = models.CharField(max_length=10,default='1')
eng_name = models.CharField(max_length=50,default='1')
name = models.CharField(max_length=100,default='1')
card = models.BooleanField(default=True)
door = models.BooleanField(default=False)
descrip = models.CharField(max_length=1000,default="",blank=True)
upload = models.FileField()
def __str__(self):
return self.name
class Example(models.Model):
filename = models.CharField(max_length=150)
cata = models.CharField(max_length=150)
description = models.CharField(max_length=500)
add_time = models.DateTimeField(auto_now_add=True)
# image = models.ImageField(max_length=100, upload_to=our_upload_to, default='ourwork/default/default.png', verbose_name='图片')
# upload = models.FileField()
def __str__(self):
return self.filename
...
这是我在控制台中运行的命令。
python .\manage.py makemigrations ourwork
然后我得到了:
Migrations for 'ourwork':
ourwork\migrations\0001_initial.py
- Create model Card
- Create model Entry
- Create model Example
- Create model Project
- Create model Work
- Add field work to entry
- Add field test_cata to card
python .\manage.py migrate
然后我得到了:
Operations to perform:
Apply all migrations: admin, auth, contenttypes, ourwork, sessions
Running migrations:
No migrations to apply.
我只想在模型中进行更改。 T_T