cherrylatte cherrylatte - 1 year ago 138
Python Question

having trouble with mysql migration (can't multiply sequence by non-int of type 'tuple')

I am havnig troulble about migrating..I first tried

python migrate qablog

and didn't work. so I tried

python migrate qablog --fake-initial

and didn't work too.. so I googled again and some people were talking about changing the so I changed some things like changing USE_TZ to false ..

python makemigrations qablog

worked well though...can anyone help me with this? ..
python version: 3.4.4
mysql server version: 5.7
django version: 1.10.3

The error log is like below:

C:\inetpub\wwwroot\test>python 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 "", line 22, in <module>
File "C:\Python34\lib\site-packages\django\core\management\", line
367, in execute_from_command_line
File "C:\Python34\lib\site-packages\django\core\management\", line
359, in execute
File "C:\Python34\lib\site-packages\django\core\management\", line 294,
in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Python34\lib\site-packages\django\core\management\", line 345,
in execute
output = self.handle(*args, **options)
File "C:\Python34\lib\site-packages\django\core\management\commands\
", line 224, in handle
self.verbosity, self.interactive, connection.alias, apps=post_migrate_apps,
File "C:\Python34\lib\site-packages\django\core\management\", line 53, i
n emit_post_migrate_signal
File "C:\Python34\lib\site-packages\django\dispatch\", line 191,
in send
response = receiver(signal=self, sender=sender, **named)
File "C:\Python34\lib\site-packages\django\contrib\auth\management\
", line 83, in create_permissions
File "C:\Python34\lib\site-packages\django\db\models\", line 452, in b
ids = self._batched_insert(objs_without_pk, fields, batch_size)
File "C:\Python34\lib\site-packages\django\db\models\", line 1068, in
self._insert(item, fields=fields, using=self.db)
File "C:\Python34\lib\site-packages\django\db\models\", line 1045, in
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Python34\lib\site-packages\django\db\models\sql\", line 10
53, in execute_sql
for sql, params in self.as_sql():
File "C:\Python34\lib\site-packages\django\db\models\sql\", 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\", 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'


#!/usr/bin/env python
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "swingqa.settings")
from import execute_from_command_line
except ImportError:
# The above import may fail for some other reason. Ensure that the
# issue is really that Django is missing to avoid masking other
# exceptions on Python 2.
import django
except ImportError:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"


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(
published_date = models.DateTimeField(
blank=True, null=True)

def publish(self):
self.published_date =

def __str__(self):
return self.title

and for the migration file.. I looked inside the qablog > migrations folder and there are init and 0001_initial file.. init file is empty (it's just blank inside) and 0001_ initial file is like below


# -*- 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 = [

operations = [
('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(,
('published_date', models.DateTimeField(blank=True, null=True)),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),

I'd really appreciate for some help :-)

Answer Source

found a solution to this question by myself :-)

I don't really know the reason but

if you change file in this path below C:\Python34\Lib\site-packages\mysql\connector\django

especially the part where def bulk_insert_sql function is,,from

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

to ...

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

there will be no errors in doing python migrate qablog command.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download