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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With