Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python mysql迁移有问题(不能将序列乘以类型为';tuple';的非int)_Python_Mysql_Django - Fatal编程技术网

Python mysql迁移有问题(不能将序列乘以类型为';tuple';的非int)

Python mysql迁移有问题(不能将序列乘以类型为';tuple';的非int),python,mysql,django,Python,Mysql,Django,我正在为迁移而烦恼1.我第一次尝试了 python manage.py迁移日志 但没有起作用。所以我试过了 python manage.py migrate qablog --fake-initial 而且也不管用。。所以我又在谷歌上搜索了一遍,有人在谈论更改设置。py所以我改变了一些事情,比如将USE_TZ改为false python manage.py makemigrations日志 不过效果很好…有人能帮我吗。。 python版本:3.4.4 mysql服务器版本:5.7 django

我正在为迁移而烦恼1.我第一次尝试了

python manage.py迁移日志

但没有起作用。所以我试过了

python manage.py migrate qablog --fake-initial
而且也不管用。。所以我又在谷歌上搜索了一遍,有人在谈论更改设置。py所以我改变了一些事情,比如将USE_TZ改为false

python manage.py makemigrations日志

不过效果很好…有人能帮我吗。。 python版本:3.4.4 mysql服务器版本:5.7 django版本:1.10.3

错误日志如下所示:

C:\inetpub\wwwroot\test>python manage.py migrate qablog --fake-initial
Operations to perform:
  Apply all migrations: qablog
Running migrations:
  Applying contenttypes.0001_initial... FAKED
  Applying auth.0001_initial... OK
  Applying qablog.0001_initial... OK
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
367, in execute_from_command_line
    utility.execute()
  File "C:\Python34\lib\site-packages\django\core\management\__init__.py", line
359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 294,
 in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Python34\lib\site-packages\django\core\management\base.py", line 345,
 in execute
    output = self.handle(*args, **options)
  File "C:\Python34\lib\site-packages\django\core\management\commands\migrate.py
", line 224, in handle
    self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps,
plan=plan,
  File "C:\Python34\lib\site-packages\django\core\management\sql.py", line 53, i
n emit_post_migrate_signal
    **kwargs
  File "C:\Python34\lib\site-packages\django\dispatch\dispatcher.py", line 191,
in send
    response = receiver(signal=self, sender=sender, **named)
  File "C:\Python34\lib\site-packages\django\contrib\auth\management\__init__.py
", line 83, in create_permissions
    Permission.objects.using(using).bulk_create(perms)
  File "C:\Python34\lib\site-packages\django\db\models\query.py", line 452, in b
ulk_create
    ids = self._batched_insert(objs_without_pk, fields, batch_size)
  File "C:\Python34\lib\site-packages\django\db\models\query.py", line 1068, in
_batched_insert
    self._insert(item, fields=fields, using=self.db)
  File "C:\Python34\lib\site-packages\django\db\models\query.py", line 1045, in
_insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "C:\Python34\lib\site-packages\django\db\models\sql\compiler.py", line 10
53, in execute_sql
    for sql, params in self.as_sql():
  File "C:\Python34\lib\site-packages\django\db\models\sql\compiler.py", line 10
38, in as_sql
    result.append(self.connection.ops.bulk_insert_sql(fields, placeholder_rows))

  File "C:\Python34\lib\site-packages\mysql\connector\django\operations.py", lin
e 223, in bulk_insert_sql
    return "VALUES " + ", ".join([items_sql] * num_values)
TypeError: can't multiply sequence by non-int of type 'tuple'
[models.py]

from django.db import models
from django.utils import timezone


class Post(models.Model):
    author = models.ForeignKey('auth.User')
    title = models.CharField(max_length=200)
    text = models.TextField()
    created_date = models.DateTimeField(
            default=timezone.now)
    published_date = models.DateTimeField(
            blank=True, null=True)

def publish(self):
    self.published_date = timezone.now()
    self.save()

def __str__(self):
    return self.title
对于迁移文件。。我查看了qablog>migrations文件夹,其中有init和0001_初始文件。。init文件为空(内部为空),0001_uu初始文件如下所示

[0001_首字母.py]

# -*- coding: utf-8 -*-
# Generated by Django 1.10.3 on 2016-11-10 07:56
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        migrations.CreateModel(
            name='Post',
            fields=[
                ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
                ('title', models.CharField(max_length=200)),
                ('text', models.TextField()),
                ('created_date', models.DateTimeField(default=django.utils.timezone.now)),
                ('published_date', models.DateTimeField(blank=True, null=True)),
                ('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
            ],
        ),
    ]

非常感谢您的帮助:-)

我自己找到了这个问题的解决方案:-)

我真的不知道原因,但是

如果更改下面此路径中的operations.py文件 C:\Python34\Lib\site packages\mysql\connector\django

特别是def bulk_insert_sql函数是、的部分

 def bulk_insert_sql(self, fields, num_values):
        items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
        return "VALUES " + ", ".join([items_sql] * num_values)

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 manage.py migrate qablog命令时不会出现错误。

我自己找到了这个问题的解决方案:-)

我真的不知道原因,但是

如果更改下面此路径中的operations.py文件 C:\Python34\Lib\site packages\mysql\connector\django

特别是def bulk_insert_sql函数是、的部分

 def bulk_insert_sql(self, fields, num_values):
        items_sql = "({0})".format(", ".join(["%s"] * len(fields)))
        return "VALUES " + ", ".join([items_sql] * num_values)

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 manage.py migrate qablog命令时不会出现错误。

发布相关迁移文件您可以在问题中添加模型和迁移文件吗?我编辑了发布相关迁移文件您可以在问题中添加模型和迁移文件吗