Skip to main content
 首页 » 编程设计

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

2024年10月17日31Leo_wl

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

错误如下。

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

谁能帮帮我?

谢谢

这是我的 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