python - Django 错误 - django.db.utils.DatabaseError : Data truncated for column 'applied' at row 1

标签 python django python-3.5

我在执行python manage.py migrate时遇到了一个奇怪的问题。

下面是错误。

django.db.utils.DatabaseError: Data truncated for column 'applied' at row 1

enter image description here

有人可以帮助我吗?

谢谢

这是我的 models.py 数据

# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
#   * Rearrange models' order
#   * Make sure each model has one field with primary_key=True
#   * Make sure each ForeignKey has `on_delete` set to the desired behavior.
#   * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from __future__ import unicode_literals

from django.db import models


class Threads(models.Model):
    date = models.DateTimeField(db_column='Date', blank=True, null=True)  # Field name made lowercase.
    supplier = models.CharField(db_column='Supplier', max_length=45, blank=True, null=True)  # Field name made lowercase.
    activethreads = models.CharField(db_column='ActiveThreads', max_length=45, blank=True, null=True)  # Field name made lowercase.
    threadscreated = models.CharField(db_column='ThreadsCreated', max_length=45, blank=True, null=True)  # Field name made lowercase.
    ipaddress = models.CharField(db_column='IPAddress', max_length=45, blank=True, null=True)  # Field name made lowercase.

    class Meta:
        managed = False
        db_table = 'Threads'


class DjangoContentType(models.Model):
    name = models.CharField(max_length=100)
    app_label = models.CharField(max_length=100)
    model = models.CharField(max_length=100)

    class Meta:
        managed = False
        db_table = 'django_content_type'
        unique_together = (('app_label', 'model'),)


class DjangoMigrations(models.Model):
    app = models.CharField(max_length=255)
    name = models.CharField(max_length=255)
    applied = models.DateTimeField()

    class Meta:
        managed = False
        db_table = 'django_migrations'

最佳答案

下面的 URL 提到了我的问题的解决方案,这是最新版本 Django 的一个错误。您需要在settings.py中更改USE_TZ = False

Incorrect datetime value when setting up Django with MySQL

完成上述更改后,您将在运行“python manage.py migrate”时遇到不同的问题,这将给您带来以下错误

TypeError: can't multiply sequence by non-int of type 'tuple'

对于这个问题,请引用下面提到的 Chris Barrett 解决方案

https://bitbucket.org/Manfre/django-mssql/issues/80/error-when-using-django-19

您需要在 versions/3.5.2/lib/python3.5/site-packages/mysql/connector/django/operations.py 中进行所需的更改(检查您的设置)并进行更改

def bulk_insert_sql(self, fields, placeholder_rows):
        """
        Format the SQL for bulk insert
        """
        placeholder_rows_sql = (", ".join(row) for row in placeholder_rows)
        values_sql = ", ".join("(%s)" % sql for sql in placeholder_rows_sql)
        return "VALUES " + values_sql

关于python - Django 错误 - django.db.utils.DatabaseError : Data truncated for column 'applied' at row 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39764318/

相关文章:

python - 如何使用 django import-export 导入 excel 文件

django - 如何使用 django-paypal 进行 paypal 自适应支付?

python - 无法使用 Django 2.1 和 Python 3.5 创建自定义用户模型

r - 如何指定 rmarkdown 以使用 Python3 而不是 Python 2?

python - 如何在 Pandas 系列中用 at[] 替换 set_value

python - 如何将 UNIX 查找输出作为 Python 脚本的参数传递?

python - 将函数应用于可迭代对象?

python - tkinter按钮限制命令不重复

python - Django ContextMixin 'super' 对象没有属性 'get_context_data'

python - Python 3.5 支持的 dask 版本是什么?