Click here to Skip to main content
14,694,012 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
File "<ipython-input-16-fbff936e9c99>", line 37
sql_create_projects_table = CREATE TABLE IF NOT EXISTS ACTOR {
^
SyntaxError: invalid syntax

when I write:
sql_create_projects_table = CREATE TABLE IF NOT EXISTS ACTOR {
                                    aid integer PRIMARY KEY,
                                    fname text NOT NULL,
                                    lname text NOT NULL,
                                    gender text NOT NULL
                                };


sql_create_tasks_table = CREATE TABLE IF NOT EXISTS ACTOR {
                                aid integer PRIMARY KEY,
                                fname text NOT NULL,
                                priority integer,
                                "status_id integer NOT NULL,
                                "project_id integer NOT NULL,
                                lname text NOT NULL,
                                gender text NOT NULL
                                "FOREIGN KEY (project_id) REFERENCES projects (id)
                                };


What I have tried:

I have tried a lot to correct this error
When I write:
sql_create_projects_table = """CREATE TABLE IF NOT EXISTS ACTOR {
                                    aid integer PRIMARY KEY,
                                    fname text NOT NULL,
                                    lname text NOT NULL,
                                    gender text NOT NULL
                                };"""


sql_create_tasks_table = """CREATE TABLE IF NOT EXISTS ACTOR {
                                aid integer PRIMARY KEY,
                                fname text NOT NULL,
                                priority integer,
                                "status_id integer NOT NULL,
                                "project_id integer NOT NULL,
                                lname text NOT NULL,
                                gender text NOT NULL
                                "FOREIGN KEY (project_id) REFERENCES projects (id)
                                };"""


everything remains fine but """ means comments and no table generated in the db file.
Posted
Updated 31-May-20 21:35pm
v2
Comments
A. B. Dinshaa 1-Jun-20 2:32am
   
File "<ipython-input-21-16e265b393f1>", line 37
sql_create_projects_table = CREATE TABLE IF NOT EXISTS ACTOR {
^
SyntaxError: invalid syntax

The ^ symbole is on TABLE not in the start

1 solution

Shouldn't that be a string? It's trying to process your SQL command as Pyuthon code ...
   
Comments
A. B. Dinshaa 1-Jun-20 2:47am
   
Do you mean we have to write SQL command in these """ quotes?
Eg: """SQL command"""

This way no table is getting generated in db file. What to do with it?
A. B. Dinshaa 1-Jun-20 4:07am
   
Indentation is also involved everywhere

# create a database connection
conn = create_connection(database)

# create tables
if conn is not None:
# create ACTOR table
create_table(conn, sql_create_ACTOR_table)

# create MOVIE table
create_table(conn, sql_create_MOVIE_table)

When I add one table the program is giving no error. When I add two tables the program is giving following error

near ")": syntax error

How to correct this syntax error?

Are the people answering are bots or humans?
A. B. Dinshaa 4-Jun-20 3:50am
   
Such errors were coming on spyder IDE not on jupyter notebook so I stopped using spyder IDE the only problem is jupyter is not giving any output at all which I am trying to figure out and if I require I am going to disturb you later for the above mentioned purpose.
Secondly jupyter is considered as better and latest as it is browser based and what I know is everything is getting browser based fast.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900