1

I am working on project 1 of python and javascript web programming and have no clue why it just can't create table. The coding execute without returning any error. Below is the code and I really appreciate some help. Thank you!

import os

from sqlalchemy import create_engine

from sqlalchemy.orm import scoped_session, sessionmaker

DATABASE_URL = "postgres://wzmsxnmxhimb....."

engine = create_engine(os.getenv("DATABASE_URL"))

db = scoped_session(sessionmaker(bind=engine))

def main():
    
db.execute("CREATE TABLE books (id SERIAL PRIMARY KEY,isbn INTEGER NOT NULL,title VARCHAR NOT NULL,author VARCHAR NOT NULL,year INTEGER NOT NULL)")
    
db.commit
    
print ("done")

if __name__ == "__main__":

        main()

2 Answers 2

2

DATABASE_URL should be an environment variable.

You can set it via the cmd-line with export DATABASE_URL="postgres://jyszivev..." on Mac or set DATABASE_URL="postgres://jyszivev..." on Windows.

by the way...you can create the table also using adminer.cs50.net

0

I guess you didn't invoke the db.commit method Try invoking the db.commit() the right way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .