2

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)
2
  • The actual TypeError: documents must be a non-empty list is from the pymongo driver and means what it says, as it got an "empty list" when it expected input. Did you actually run a python manage.py makemigrations first? Because the error seems to indicate there's "nothing to do". You said you "deleted", but AFIAK you still need to run the makemigrations first. Commented Mar 16, 2019 at 7:25
  • I did python manage.py makemigrations first then run python manage.py migrate , still no luck Commented Mar 16, 2019 at 7:32

8 Answers 8

10

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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

1 Comment

Did this and worked. But what is saw -if I do understand well- is install last version of sqlpars. I think this because the output Collecting sqlparse==0.2.4 Using cached https://files.pythonhosted.org/packages/65/85/20bdd72f4537cf2c4d5d005368d502b2f464ede22982e724a82c86268eda/sqlparse-0.2.4-py2.py3-none-any.whl Installing collected packages: sqlparse Successfully installed sqlparse-0.3.1
2

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.

1 Comment

Thanks it worked !!! , the problem in on djongo , not sqlprase
0

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

Comments

0

Just install sqlprase to solve this.

Download it github sqlprase

pip install filename.zip

Comments

0

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

Comments

0

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

 pip install sqlparse==0.2.4 

Comments

-2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.