一次在使用orm進行聯表查詢的時候,出現 Python int too large to convert to C long 的問題:
在分析錯誤之后,在錯誤最后面提示中有:
File "F:\python\python3.6\lib\sqlite3\dbapi2.py", line 64, in convert_date return datetime.date(*map(int, val.split(b"-")))
在查看我的model.py文件的時候我的模型定義是:
from django.db import models # Create your models here. class Book(models.Model): nid = models.AutoField(primary_key=True) title = models.CharField(max_length=64) publishDate = models.DateField() price = models.DecimalField(max_digits=5, decimal_places=2) publish = models.ForeignKey(to="Publish", to_field="nid", on_delete=models.CASCADE) authors = models.ManyToManyField(to="Author") class Author(models.Model): nid = models.AutoField(primary_key=True) name = models.CharField(max_length=32) age = models.IntegerField() # 作者和作者信息一對一 AuthorDetail=models.OneToOneField(to="AuthorDetail",on_delete=models.CASCADE) class AuthorDetail(models.Model): nid = models.AutoField(primary_key=True) # birthday = models.DateField() # 特別是這一行進行注視后,就不會再提示 Python int too large to convert to C long 了
# 或則將此行改為
birthday = models.DateTimeField()
tetephone = models.BigIntegerField() addr = models.CharField(max_length=64) class Publish(models.Model): nid = models.AutoField(primary_key=True) name = models.CharField(max_length=32) city = models.CharField(max_length=32) email = models.EmailField()