我已經App12/models.py模塊爲:類型錯誤:INT()參數必須是字符串或數字,而不是 'datetime.datetime'
from django.db import models
class Question(models.Model):
ques_text=models.CharField(max_length=300)
pub_date=models.DateTimeField('Published date')
def __str__(self):
return self.ques_text
class Choice(models.Model):
# question=models.ForeignKey(Question)
choice_text=models.CharField(max_length=300)
votes=models.IntegerField(default=0)
def __str__(self):
return self.choice_text
然後我運行CMDS
python manage.py makemigrations App12
python manage.py migrate
Question.objects.create(ques_text="How are you?",pub_date='timezone.now()')
# and (ques_text="What are you doing?",pub_date='timezone.now()')
然後,我意識到這個問題,並選擇模型應該是外鍵關係和:
,然後在問題模型進入2條記錄取消對上述評論的語句在型號代碼
當我運行「python manage.py makemigrations App12
」,它運行良好,但在那之後,我收到
"TypeError: int() argument must be a string or a number, not 'datetime.datetime"
錯誤,當我運行「蟒蛇manage.py遷移「命令。
任何人都可以幫助我。我現在可以在Choice模型和Question模型之間添加外鍵關係。
回溯是否提到錯誤在哪裏? – dietbacon
你所評論的ForeignKey有什麼問題? – dietbacon
完全沒有問題。但是當我在做代碼時,發生了這個問題。首先,我忘了添加外鍵關係,但在某個時間之後,我意識到問題和選擇模型之間應該存在外鍵關係。但是執行遷移命令時,它顯示了上述錯誤。爲什麼它會顯示這樣的錯誤,我如何擺脫這個問題。 – Jagat