How to solve SQLdecode error when you migrate mode

2020-07-29 23:07发布

问题:

I am new to django, I have created a project and app and I would like to connect my project to the mongodb. when I enter python manage.py migrate command , I am getting below mentioned error.

I have dropped database and cleared all migrations in the django_migration table and deleted migration files in the created migrations folder. Still getting same error.

Please help me with this. Thanks in advance

Error:

    raise TypeError("documents must be a non-empty list")
TypeError: documents must be a non-empty list

The above exception was the direct cause of the following exception:

djongo.sql2mongo.SQLDecodeError: FAILED SQL: INSERT INTO "django_migrations" ("app", "name", "applied") VALUES (%(0)s, %(1)s, %(2)s)
    Version: 1.2.31

Settings.py

DATABASES = {
    'default': {
        'ENGINE': 'djongo',
        'NAME': 'DB_name',
        'HOST':'localhost',
        # 'PORT': 27017,
        # 'USER':'',
        # 'PASSWORD':''
    },

models.py

from django.db import models

# Create your models here.
class dummy(models.Model):

    name= models.CharField(max_length=100, blank=True, null= True)

回答1:

i have solved this problem, the problem may be the version of sqlparse -- sqlparse 0.2.4 works well, but sqlparse 0.3.0 not.

pip install sqlparse==0.2.4 --user

It worked to me, good luck!!!



回答2:

After creating django project uninstall sqlparse by typing

pip3 uninstall sqlparse

Then install sqlparse version=0.2.4 by typing

pip3 install sqlparse==0.2.4

Then migrate mongodb database by typing

python3 manage.py migrate

If you are using python2 then use (pip) instead of (pip3) and (python) instead of (python3) in the command.



回答3:

I have the same issue with u, I tried with sqlite3 as the database, and the data is just like this:

so the data is not empty!!

And I tried to change the sql command as follow(line 760 at sql2mongo\query.py):

statement = statement[0]
    sm_type = statement.get_type()
    if sm_type=='INSERT':
        self._sql = 'INSERT INTO "django_migrations" ("app", "name", "applied") VALUES ("test", "windy", "2019-03-15 12:00")'

but still failed.



回答4:

Just install sqlprase can solve this.

Download it github sqlprase

pip install filename.zip!!



回答5:

Use python manage.py migrate --fake-initial the first time you migrate your project.

In setting.py add INSTALLED_APPS=[ 'APP_NAME.apps.APP_NAMEConfig', ..., ..., ]