PSET7 finance buy won't add anything to portfolio table

I am working on pset7 and my buy function won't add anything to my portfolio table. My table details are as follows:

'portfolio' ( 'user_id' INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE NOT NULL, 'name' TEXT UNIQUE NOT NULL, 'symbol' TEXT UNIQUE NOT NULL, 'price' NUMERIC NOT NULL, 'shares' INTEGER NOT NULL, 'total' INTEGER NOT NULL, 'date' DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, FOREIGN KEY (user_id) REFERENCES users(id) );

My buy code is here:

https://github.com/nattysgg/pset7/blob/master/buy.py

Thanks for any help!

Upvotes: 0

Views: 482

Answers (1)

I figured out my error. I set user_id as unique and primary key in may table, therefore the user would only have one row in the table. So it was possible to buy the first stock, but not to add further stocks in the same user. I took the unique and primary keys from user_id and set them only to symbol and it solved my problem. I hope this helps someone

Upvotes: 1

Related Questions