Opened 10 years ago

Closed 10 years ago

#23632 closed Uncategorized (worksforme)

Cannot install Stored Procedure on syncdb

Reported by: Tim-Erwin Owned by: nobody
Component: Core (Management commands) Version: 1.7
Severity: Normal Keywords: sql syncdb
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I have a simple SP which I like Django to install via a file in the sql folder:

DELIMITER $$

CREATE PROCEDURE myProcedure (IN myParam INT)
BEGIN

  DROP TEMPORARY TABLE IF EXISTS tmp;

  CREATE TEMPORARY TABLE IF NOT EXISTS tmp AS
  (SELECT 1, 2, 3);

END $$

However, I get the following error (because the statement is split into pieces):

Failed to install custom SQL for myApp.myModel model: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$ CREATE PROCEDURE myProcedure (IN myParam INT) BEGIN DROP TEMPORARY ' at line 1")

If I install sqlparse (which leaves the statement as a whole) and try again, I get this error:

Failed to install custom SQL for myApp.myModel model: (1064, "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DELIMITER $$\n\nCREATE PROCEDURE myProcedure (IN myParam INT)\nBEGIN\n\n  DROP TEMPOR' at line 1")

I guess, this is related to #3214

Change History (1)

comment:1 by Claude Paroz, 10 years ago

Resolution: worksforme
Status: newclosed

As stated in the docs, custom SQL in a sql file is deprecated in Django 1.7, and should be done with a data migration now (and a RunSQL operation).

https://docs.djangoproject.com/en/1.7/howto/initial-data/#providing-initial-sql-data
https://docs.djangoproject.com/en/1.7/topics/migrations/#data-migrations
https://docs.djangoproject.com/en/1.7/ref/migration-operations/#django.db.migrations.operations.RunSQL

Please provide us with more details if this does not address your issue.

Note: See TracTickets for help on using tickets.
Back to Top