akhil s
akhil s

Reputation: 147

How to solve SQLdecode error when you migrate models in django?

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)

Upvotes: 2

Views: 6211

Answers (8)

Zeeshan Liaqat
Zeeshan Liaqat

Reputation: 106

Please try to install the sqlparse package, using this command in the terminal.

 pip install sqlparse==0.2.4 

Upvotes: 0

binbomb
binbomb

Reputation: 31

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. Use following command:

pip install sqlparse==0.2.4 --user

Upvotes: 3

cyrille gate
cyrille gate

Reputation: 79

I have updated djongo with pip install --upgrade djongo and I have done the migrations python manage.py migrate --fake-initial and it has been fixed.

Upvotes: 2

Alex Hurtado
Alex Hurtado

Reputation: 409

I have solved it that way sqlparse==0.2.4 and djongo==1.3.3 and django==2.1.7

Upvotes: 0

Windy Wen
Windy Wen

Reputation: 1

Just install sqlprase to solve this.

Download it github sqlprase

pip install filename.zip

Upvotes: 0

Shalini
Shalini

Reputation: 1

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', ..., ..., ]

Upvotes: 0

Adnan Rahman
Adnan Rahman

Reputation: 133

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.

Upvotes: 10

Windy Wen
Windy Wen

Reputation: 1

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

enter image description here

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.

Upvotes: -2

Related Questions