我在“ models.py
”中的“服务”类中创建了一个变量“用户”,这是另一个类的外键
然后给它一个属性'default ='None'..我先运行'manage.py makemigrations
'然后运行'manage.py migrate
',但这给了我这样的错误:
packages\django\db\models\fields\__init__.py", line 965, in get_prep_value
return int(value)
ValueError: invalid literal for int() with base 10: 'None'
..所以我删除了变量'user',但是它仍然给我同样的错误! 我试图显示迁移情况,就像这样:
服务
[X] 0001_initial
[X] 0002_auto_20190126_1417
[X] 0003_auto_20190126_1423
[X] 0004_auto_20190126_1425
[X] 0005_auto_20190126_1436
[X] 0006_auto_20190127_1434
[X] 0007_auto_20190128_0915
[X] 0008_service_user
[ ] 0009_auto_20190130_1855
[ ] 0010_auto_20190130_1856
[ ] 0011_auto_20190130_1926
[ ] 0012_auto_20190130_1928
[ ] 0013_service_user
[ ] 0014_remove_service_user
[ ] 0015_service_publisher
我试图删除该变量,并设置另一个名为“ publisher”的变量,将其属性设置为“ null = True”,但它不起作用
models.py
from django.db import models
from django.urls import reverse_lazy, reverse
from firstapp.models import User_Model
class Category(models.Model):
categoryName = models.CharField(max_length=150, primary_key=True)
def __str__(self):
return self.categoryName
class Service(models.Model):
serviceTitle = models.CharField(max_length=100, primary_key=True)
deadlineDate = models.DateField(null=True, help_text='please Enter the
date in the format : year-month-day')
price = models.DecimalField(max_digits=10, decimal_places=3, null=True,
default=10.00)
serviceDescription = models.CharField(max_length=600, null=True,
default='Descripe your service')
category = models.ForeignKey(Category, related_name='categories',
on_delete=models.CASCADE, null=False, default='Engineering')
publisher = models.ForeignKey(User_Model, on_delete=models.CASCADE,
null=True)
def __str__(self):
return self.serviceTitle
def get_absolute_url(self):
return reverse('serviceDetails', kwargs={'pk':self.pk})