Skip to content

Instantly share code, notes, and snippets.

@BaronKimaru
Last active January 31, 2025 15:05
Show Gist options
  • Select an option

  • Save BaronKimaru/a1b16177d416a39ff45ac56c104dafd7 to your computer and use it in GitHub Desktop.

Select an option

Save BaronKimaru/a1b16177d416a39ff45ac56c104dafd7 to your computer and use it in GitHub Desktop.
Solve: django.db.utils.OperationalError: near ")": syntax error

My Code:

from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcore', '0066_collection_management_permissions'),
        ('wagtailforms', '0004_add_verbose_name_plural'),
        ('wagtailredirects', '0006_redirect_increase_max_length'),
        ('home', '0017_alter_orderdetailpage_options'),
    ]

    operations = [
        # migrations.RemoveField(
        #     # model_name='orderdetailpage',
        #     name='page_ptr',
        # ),
        # migrations.RemoveField(
        #     # model_name='successpage',
        #     name='page_ptr',
        # ),
        migrations.DeleteModel(
            name='MerchantHomePage',
        ),
        migrations.DeleteModel(
            name='OrderDetailPage',
        ),
        migrations.DeleteModel(
            name='SuccessPage',
        ),
    ]

Error:

return Database.Cursor.execute(self, query, params) django.db.utils.OperationalError: near ")": syntax error

Solution:

  • It occurs because you are trying to Delete a Class that has no Fields.
  • Get rid of the RemoveField section in your migration: normally such migrations have auto in their names eg 0021_auto_20211126_0955.py

Example in my case

  • Changed From:
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcore', '0066_collection_management_permissions'),
        ('wagtailredirects', '0006_redirect_increase_max_length'),
        ('wagtailforms', '0004_add_verbose_name_plural'),
        ('home', '0020_auto_20211126_0945'),
    ]

    operations = [
        migrations.RemoveField(
           model_name='orderdetailpage',
           name='page_ptr',
        ),
        migrations.DeleteModel(
            name='MerchantHomePage',
        ),
        migrations.DeleteModel(
            name='OrderDetailPage',
        ),
    ]
  • to:
from django.db import migrations


class Migration(migrations.Migration):

    dependencies = [
        ('wagtailcore', '0066_collection_management_permissions'),
        ('wagtailredirects', '0006_redirect_increase_max_length'),
        ('wagtailforms', '0004_add_verbose_name_plural'),
        ('home', '0020_auto_20211126_0945'),
    ]

    operations = [
        # ..removed the RemoveField section
        
        migrations.DeleteModel(
            name='MerchantHomePage',
        ),
        migrations.DeleteModel(
            name='OrderDetailPage',
        ),
    ]
  • Then run python manage.py migrate again and everything should be good
@pfcodes
Copy link

pfcodes commented Nov 23, 2022

thanks for this

@stefanofusai
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment