In this Python Flask Tutorial, we will be learning how to create a database using Flask-SQLAlchemy. SQLAlchemy is a great tool for working with databases …
Original source
In this Python Flask Tutorial, we will be learning how to create a database using Flask-SQLAlchemy. SQLAlchemy is a great tool for working with databases …
Original source
24 responses to “Python Flask Tutorial: Full-Featured Web App Part 4 – Database with Flask-SQLAlchemy”
i have a problem , when i try to commit in the Post database. it shows
"SQLite DateTime type only accepts Python "
sqlalchemy.exc.StatementError: (builtins.TypeError) SQLite DateTime type only accepts Python datetime and date objects as input.
i wonder what is the problem ? i followed the instructions but got that though..
Can you share the sources for flask and Django. Like from where did you learn. Cause you code like a pro and i want to do the same
i want to use mongodb(pymongo) OR mongoAlchemy here instead of SQL.plz suggest me what will be the respective changes in code.plz help me.
I hada great time running this in the terminal. Powershell – so much better
Hey Corey,
While creating users from cmdline i got an error as "sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize – can't proceed with initialization of other mappers. Triggering mapper: 'mapped class User->user'. Original exception was: Could not determine join condition between parent/child tables on relationship User.posts – there are no foreign keys linking these tables. Ensure that referencing columns are associated with a ForeignKey or ForeignKeyConstraint, or specify a 'primaryjoin' expression."
Can you please help me out
Your videos are really great ! Thanks for every things
Stupid question…but,
What is the purpose of the f in the return of the _repr_ function for the db stuff?
_repr_ (self)
return f"User({'self.user'})
when i run this I get a syntax error
on the return in the virtual enviroment
First of all thank you for great tutorials. I have a question. for Example, i have to save a passport id to database, what type of column would you use for that? These numbers do not have decimal values and there should be max input of 11
thank you so much.
ty i tweeted this
I liked this video under 20ms after I see the photo of the dude. you are the best Bro. ❤👍
it took me a couple of goes but I got it. The image file was giving me an error, but once removed all was ok. I plan to add later.
How do you use the f thing in python
Hey I created database externally through sqlite browser….how i could access the database through python.
17:04 made me so happy when you noticed that and fixed it. I had a solid 10 minutes of anxiety.
I am getting an error when I run:
User.query.all()
The error is:
TypeError: __init__() takes exactly 1 argument (2 given)
Have been doing coding since 15 years, but this is one of the best videos have seen so far. Respect!
Note: When using Postgres as Production DB, SQLAlchemy creates a table name 'user' from Class User. 'user' is a reserved table in postgres and is used for db admin users. Using pgAdmin I could not see that my table existed. My db worked but I couldn't see the table in pgAdmin sidebar. I could only see the reserved 'user' table. I had to use SELECT * FROM "user"; (double quotes) to get my data. I changed Class 'User' to 'Users' to avoid later confusion. Not sure if this is similar behavior in other dbs. Hope it saves someone a day of head scratching!
I have a quick question. Trying to do this in pycharm, but i just can seem to figure out how to create the database CMD does not work.
Hi Corey, I'm finding it difficult to setup flask-migrate, is this something you cover anywhere, I will keep trying myself, I'm using pipenv so sometimes I get confused about commands I should be running. I'm probably doing something stupid so any pointers from anyone would be great, thanks.
Hi, thanks for these nice videos.
dear Corey: it would be wonderful if you can release a video about Flask-Pymongo or Flask-MongoDB in which you can set up your own database in Mongodb that is basically a NoSQL database. many thanks in advance.
Really Great Work you do!! Now i dont mind paying for this series on udemy or any other kind. I can now ensure that only true and really contents will come from +Corey Schafer
Hi Corey,
Your videos are very helpful!
What is the best way to learn about converting SQL queries to SQLAlchemy? I'm currently struggling with joining three tables. It's easy enough to do in SQL however I haven't yet figured out how to convert this into SQLAlchemy. Examples at stackoverflow.com and SQLAlchemy.org haven't helped.
Would you mind providing an example of a SQLAlchemy join?