I cannot access one of the tables in my database. I can't even delete the table by myself, so I am not sure what to do. Here is the error:
ERROR 1064 (42000): 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 'match' at line 1
So this error appears every time I am doing an operation on that table (describe, select, drop, etc.)
I have deleted the model from my code, but that doesn't remove the table from the db.
This is a bit of speculation. But the error is referring to match. It might not be obvious, but match is a reserved word in MySQL. It is used for full-text searches.
If you have a column or table named match and it is being referred to without escape characters (backticks), then you would likely get an error like this.
The thing to do is to fix the name of the table/column so it does no conflict with a reserved word.
Related
I'm running a python db migration script (Flask-Migrate) and have added the alembic.ddl.imp import DefaultImpl to get around the first set of errors but now I'm getting the following. I'm trying to use this script to set up my tables and database in snowflake. What am I missing? Everything seems to be working and I can't seem to find any help on this particular error in the snowflake documentation. I would assume that the snowflake sqlalchemy connector would address the creation of a unique index.
The script so far does create several of the tables, but when it gets to this part it throws the error.
> sqlalchemy.exc.ProgrammingError:
> (snowflake.connector.errors.ProgrammingError) 001003 (42000): SQL
> compilation error: syntax error line 1 at position 7 unexpected
> 'UNIQUE'. [SQL: CREATE UNIQUE INDEX ix_flicket_users_token ON
> flicket_users (token)] (Background on this error at:
> http://sqlalche.me/e/f405)
Snowflake does not have INDEX objects, so any CREATE ... INDEX statement will fail.
With Snowflake, you have to trust the database to organize your data with micro partitions and build a good access plan for your queries.
You will feel uneasy at first, but eventually stop worrying.
Bleeding edge solutions will require monitoring/tuning performance using the query log, however.
Nothing new here.
I general I know how to execute custom SQL on syncdb. I'm using Django 1.7 which has migrate, but due to some special fields my app is not yet ready for it, so Django falls back to syncdb. At least now it is using sqlparse in order to properly split the contents of the file into single statements.
However, with sqlparse installed, Django sends the whole file at once and I get
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\nDROP PROCEDURE IF EXISTS myProcedure //\n\nCREA' at line 1")
When I uninstall sqlparse, Django does not respect the DELIMITER statement and thus produces chunks of codes that don't make sense at all.
I tried the trick with putting a "-- comment" behind any line with a semicolon does not work, comments are removed.
As mentioned in comment of here,
The delimiter is used only by mysql client (not on API, driver ... etc).
So, it won't work.
I encountered similar problem when using db.execute(sql_file) using south (for my django migration) where my sql_file had
DROP PROCEDURE IF EXIATS ....
DELIMITER //
CREATE PROCEDURE ....
BEGIN
....
END
...
I removed the DROP and DELIMITER bits, and added 'label' to the procedure creation and it works for me:
CREATE PROCEDURE xxxx
label: BEGIN
....
;
END label
I've been running a Django application on my local machine and am trying to push it to appengine. One of the queries I was making before that never caused any trouble was:
ALTER TABLE Records ADD COLUMN Id
but when I try to execute this query on Cloud SQL, I get this error:
Error 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 '' at line 1
What am I doing wrong?
The syntax for Alter table is
ALTER TABLE table_name ADD column_name datatype
You forgot to specify the datatype for Id
Something like
ALTER TABLE Records ADD COLUMN Id INT
I am using python 2.7 for a specific job. I am connecting to MSSQL Server (2008) using FreeTDS. I can make some simple select queries but when I try to run a parametrised query I got an error:
('HY004', '[HY004] [FreeTDS][SQL Server]Invalid data type (0) (SQLBindParameter)')
Here is my query:
query = u"UPDATE table SET column1=? WHERE column2=?"
cursor.execute(query,[param1, param2])
However the same code on live works fine.
I have skimmed so many thread in various forums but they all seem misleading and I am really confused.
What is my actual problem and what do you suggest?
Edit: I've added query.
I know this is a super old thread, but I came across this same problem and the solution for me was to type cast the variables. For instance:
query = u"UPDATE table SET column1=? WHERE column2=?"
cursor.execute(query,[str(param1), str(param2)])
In this case it doesn't really matter what type the parameters are as it will be converted to a string.
How to check if the table in database exist before creating it by using Python?
I would like to check if it exist then drop the table. If not, then create..
Also, how to display error if there are some errors in the codes of database?
(If in PHP. Codes will be die("....."); for Error Handling.. So what should I use in Python?)
Any advice?
From the MySQL manal use
CREATE table IF NOT EXISTS ...
To create a table if it doesn't exist. That might even be standard SQL (not sure but it will work in sqlite too)!
As for your second question "how to display error if there are some errors in the codes of database?" not sure exactly what you mean. but if MySQL returns an error then the database module will turn it into a python exception - see this StackOverflow question for some discussion