Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is sqlparse required and if yes, how do you install it?

Tags:

django

I have two different Django projects. One uses PostgreSQL and one uses MySQL.

In the postgres version, this worked.

    migrations.RunSQL('''CREATE OR REPLACE view skill_ranked_by_person_view AS 
    SELECT link.id
    , skill.id skill_id
    , person.id person_id
    , concat( skill_rank.rank, ' — ', replace(
        concat(first_name,' ', middle_name, ' ' , last_name)
    , '  ', ' '), ' (', skill_rank.name, ')' ) person
    -- , * 
    FROM people_personskill link
    INNER JOIN people_skill skill
    ON link.skill_id = skill.id
    INNER JOIN people_skillrank skill_rank
    ON skill_rank.id = link.skill_rank_id
    INNER JOIN people_person person 
    ON link.person_id = person.id
    ORDER BY skill.rank desc, skill_rank.rank DESC'''),

In the MySQL version, this failed.

    migrations.RunSQL('''
    create or replace view client_view as
    select IDAutoInteger as id
    , concat(IDText,' - ', NameText) `client` 
    from clients 
    where IDText is not null
    order by concat(IDText,' - ', NameText) ;
    '''),

with

"sqlparse is required if you don't split your SQL "
django.core.exceptions.ImproperlyConfigured: sqlparse is required if you don't split your SQL statements manually.

Neither project has sqlparse in the requirements.txt file.

Is sqlparse required and if yes, how do you install it?

like image 948
Keith John Hutchison Avatar asked May 17 '18 07:05

Keith John Hutchison


2 Answers

The solution was simple.

pip install sqlparse

I added sqlparse to requirements.txt in the MySQL project.

I checked if sqlparse was installed in the project that did not require it and it wasn't installed. I'm not sure why one project required it and one did not but the resolution of the issue was to just install sqlparse via pip.

like image 60
Keith John Hutchison Avatar answered Oct 22 '22 02:10

Keith John Hutchison


As per the documentation of Django:

There are several optional Django features that require third-party Python packages that (intentionally) aren't specified as install_requires dependencies in setup.py, since not everyone would want them installed.

And then they listed sqlparse:

  • sqlparse for multi-line SQL statements for migrations RunSQL

Source

like image 32
Tharwat Abouhelal Avatar answered Oct 22 '22 04:10

Tharwat Abouhelal