Trying to migrate in Django 1.9 — strange SQL error “django.db.utils.OperationalError: near ”)“: syntax error”

前端 未结 2 650
予麋鹿
予麋鹿 2021-02-13 09:31

I don\'t have a clue what\'s causing this error. It appears to be a bug that there isn\'t a fix for. Could anyone tell give me a hint as to how I might get around this? It\'s

相关标签:
2条回答
  • 2021-02-13 10:10

    Edit base.py in the lines that breaks and update it to:

    def execute(self, query, params=None):
        if params is None:
            if '()' not in str(query):
                return Database.Cursor.execute(self, query)
        query = self.convert_query(query)
        if '()' not in str(query):
            return Database.Cursor.execute(self, query, params)
    
    0 讨论(0)
  • 2021-02-13 10:19

    This appears to be the line that's causing the errror:

     INSERT INTO "optilab_lasersubstrate" () SELECT  FROM "optilab_lasersubstrate__old";
    

    You are usually expected to have a list of columns in those parenthesis. Eg INSERT INTO "optilab_lasersubstrate" (col1,col2,etc) however the migration has produced a blank set! Similarly the SELECT FROM portion should read as SELECT col1,col2 FROM. By some strange set of events you appear to have managed to create a table with no columns!!

    I see from your migration file that you are anyway dropping this table. So there isn't any reason to struggle with the RemoveField portion. It's code associated with the RemoveField that's causing the error. Change your migration as follows:

    class Migration(migrations.Migration):
    
        dependencies = [
            ('optilab', '0005_test'),
        ]
    
        operations = [
            migrations.DeleteModel(
                name='LaserSubstrate',
            ),
            migrations.DeleteModel(
                name='WaveguideSubstrate',
            ),
        ]
    
    0 讨论(0)
提交回复
热议问题