运行包含以下创建过程的函数后:
client_daily.objects.create(client_id=c,title=c.title,products=product_list,categories=categories[:-2],product_team=product_team[:-2],pcategory=pcategory[:-2],date=date)
我想出了错误:
追踪:
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py" in execute
112. return self.cursor.execute(query, args)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/cursors.py" in execute
209. res = self._query(query)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/cursors.py" in _query
315. db.query(q)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/connections.py" in query
239. _mysql.connection.query(self, query)
The above exception ((1406, "Data too long for column 'product_team' at row 1")) was the direct cause of the following exception:
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
39. response = get_response(request)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
187. response = self.process_exception_by_middleware(e, request)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
185. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/www/wwwroot/geolocator/intranet/views.py" in cron_job_functions
2103. message=my_scheduled_job()
File "/www/wwwroot/geolocator/intranet/views.py" in my_scheduled_job
882. client_daily.objects.create(client_id=c,title=c.title,products=product_list,categories=categories[:-2],product_team=product_team[:-2],pcategory=pcategory[:-2],date=date)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/query.py" in create
399. obj.save(force_insert=True, using=self.db)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/base.py" in save
796. force_update=force_update, update_fields=update_fields)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/base.py" in save_base
824. updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/base.py" in _save_table
908. result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/base.py" in _do_insert
947. using=using, raw=raw)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/manager.py" in manager_method
85. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/query.py" in _insert
1045. return query.get_compiler(using=using).execute_sql(return_id)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/models/sql/compiler.py" in execute_sql
1054. cursor.execute(sql, params)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
79. return super(CursorDebugWrapper, self).execute(sql, params)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/utils.py" in __exit__
94. six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/utils/six.py" in reraise
685. raise value.with_traceback(tb)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/utils.py" in execute
64. return self.cursor.execute(sql, params)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py" in execute
112. return self.cursor.execute(query, args)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/cursors.py" in execute
209. res = self._query(query)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/cursors.py" in _query
315. db.query(q)
File "/www/wwwroot/geolocator/geolocator_venv/lib/python3.7/site-packages/MySQLdb/connections.py" in query
239. _mysql.connection.query(self, query)
Exception Type: DataError at /cron_job_functions/
Exception Value: (1406, "Data too long for column 'product_team' at row 1")
这是我的模特:
class client_daily(models.Model):
client_id = models.ForeignKey(client_coordinates, null=True, blank=True,related_name='customers', verbose_name=u'πελάτες',on_delete = models.CASCADE)
title = models.CharField(max_length=200, blank=True, null=True)
products = models.CharField(max_length=4000, blank=True, null=True)
categories = models.CharField(max_length=200, blank=True, null=True,db_index=True)
product_team = models.CharField(max_length=350, blank=True, null=True,db_index=True)
pcategory = models.CharField(max_length=200, blank=True, null=True,db_index=True)
date = models.DateField(db_index=True)
我尝试通过执行python manage.py migrate --fake
来解决此问题,但它一直在抱怨。
我该如何解决?
实际上,CharField仅对大多数数据库后端支持256个字符的max_length(您可以检查数据库后端以找到该值)。您尝试在product_team中传递的值超过256个字符。这就是为什么您得到错误。将您的product_team更改为没有任何此类限制的TextField。
您在产品领域也会遇到同样的问题。因此,我建议您也对此进行更改