1

I am working with Python and SQLite. I am constantly getting this message

"near ")": syntax error".

I tried to add a semi-colon to all the queries but still, I get this error message.

tables.append("""
                        CREATE TABLE IF NOT EXISTS payment (
                            p_id integer PRIMARY KEY,
                            o_id integer NON NULL,
                            FOREIGN KEY(o_id) REFERENCES orders(o_id),
                        );"""
                        )

3 Answers 3

5

You have a comma before the final closing ). Simply remove it.

i.e. use :-

tables.append("""
                        CREATE TABLE IF NOT EXISTS payment (
                            p_id integer PRIMARY KEY,
                            o_id integer NON NULL,
                            FOREIGN KEY(o_id) REFERENCES orders(o_id)
                        );"""
                        )
Sign up to request clarification or add additional context in comments.

1 Comment

I figured it out. I was about to answer it myself by you guys did it first.
4

Remove the comma in the end of the FOREIGN KEY(o_id) REFERENCES orders(o_id),

The working code will be:

tables.append("""
    CREATE TABLE IF NOT EXISTS payment (
        p_id integer PRIMARY KEY,
        o_id integer NON NULL,
        FOREIGN KEY(o_id) REFERENCES orders(o_id)
    );"""
)

1 Comment

I figured it out. I was about to answer it myself by you guys did it first.
0

Try this:

tables = []
tables.append("""
CREATE TABLE IF NOT EXISTS payment p_id integer PRIMARY KEY,
o_id integer NON NULL FOREIGN KEY(o_id) REFERENCES orders(o_id),
              """)                                
print(tables)

1 Comment

There was a , after the last statement. Removing it fixed the bug.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.