- Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

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 because it allows us to interact with the database in an Object-Oriented manner, which is very intuitive once we get used to it. We will be usi...
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 because it allows us to interact with the database in an Object-Oriented manner, which is very intuitive once we get used to it. We will be using a SQLite database to get us started and then move on to a Postgres database when we deploy the application. Let's get started...

The code for this series can be found at:
https://github.com/CoreyMSchafer/code_snippets/tree/master/Python/Flask_Blog


✅ Support My Channel Through Patreon:
https://www.patreon.com/coreyms

✅ Become a Channel Member:
https://www.youtube.com/channel/UCCezIgC97PvUuR4_gbFUs5g/join

✅ One-Time Contribution Through PayPal:
https://goo.gl/649HFY

✅ Cryptocurrency Donations:
Bitcoin Wallet - 3MPH8oY2EAgbLVy7RBMinwcBntggi7qeG3
Ethereum Wallet - 0x151649418616068fB46C3598083817101d3bCD33
Litecoin Wallet - MPvEBY5fxGkmPQgocfJbxP6EmTo5UUXMot

✅ Corey's Public Amazon Wishlist
http://a.co/inIyro1

✅ Equipment I Use and Books I Recommend:
https://www.amazon.com/shop/coreyschafer

▶️ You Can Find Me On:
My Website - http://coreyms.com/
My Second Channel - https://www.youtube.com/c/coreymschafer
Facebook - https://www.facebook.com/CoreyMSchafer
Twitter -
Instagram - https://www.instagram.com/coreymschafer/

#Python #Flask

#python #flask #flask tutorial #sqlalchemy #flask-sqlalchemy #sqlite #database #python database #flask database #python flask tutorial #python flask tutorial for beginners #flask tutorial for beginners #python tutorial #python web #python web application #flask web framework #web framework #corey schafer #python (programming language) #sql alchemy #python flask
It looks like the SQLALCHEMY_DATABASE_URI isn't set, which basically is the location to your database. See how I set that at  in the video? Are you sure you're spelling it correctly and putting the underscores in the correct place? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

It looks like the SQLALCHEMY_DATABASE_URI isn't set, which basically is the location to your database. See how I set that at in the video? Are you sure you're spelling it correctly and putting the underscores in the correct place?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:03:00 - 00:29:58
@  are we inheriting the Model class to User class? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

@ are we inheriting the Model class to User class?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:04:44 - 00:29:58
@ you created db.Model, what is this .Model ? is it the method within SQLAlchemy? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

@ you created db.Model, what is this .Model ? is it the method within SQLAlchemy?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:05:00 - 00:29:58
when you created the User table at , why did you not need to use the __init__ method? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

when you created the User table at , why did you not need to use the __init__ method?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:05:00 - 00:29:58
I get this error at , "unresolved attribute reference 'Column' for class. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

I get this error at , "unresolved attribute reference 'Column' for class.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:05:03 - 00:29:58
.ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> from flaskblog import dbTraceback (most recent call last):File "<stdin>", line 1, in <module>ModuleNotFoundError: No module named 'flaskblog' - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

.ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit (AMD64)] on win32Type "help", "copyright", "credits" or "license" for more information.>>> from flaskblog import dbTraceback (most recent call last):File "<stdin>", line 1, in <module>ModuleNotFoundError: No module named 'flaskblog'

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:05:20 - 00:29:58
Hi Mohamed - If you go to  in the video, Corey creates a __repr__ definition. This definition determines what is displayed when the object (the instance of the user class in this case) is printed to the screen, and you will see that Corey did not include the password or id in the definition, hence it is missing when the user object is printed to the screen. It's worth experimenting with the repr definition, so you can see how it works; perhaps add the user id so it is printed to the screen. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Hi Mohamed - If you go to in the video, Corey creates a __repr__ definition. This definition determines what is displayed when the object (the instance of the user class in this case) is printed to the screen, and you will see that Corey did not include the password or id in the definition, hence it is missing when the user object is printed to the screen. It's worth experimenting with the repr definition, so you can see how it works; perhaps add the user id so it is printed to the screen.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:08:20 - 00:29:58
I am noobie in web app .. can someone please give the code  he did on  for python 2.6 ... Pls plz I need it - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

I am noobie in web app .. can someone please give the code he did on for python 2.6 ... Pls plz I need it

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:09:00 - 00:29:58
made me so happy when you noticed that and fixed it. I had a solid 10 minutes of anxiety. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

made me so happy when you noticed that and fixed it. I had a solid 10 minutes of anxiety.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:17:04 - 00:29:58
😁 ,,, Great tutorial - Easily understandable -  Thank you Very much - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

😁 ,,, Great tutorial - Easily understandable - Thank you Very much

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:17:05 - 00:29:58
I'm stuck on , I'm using Pycharm and I don't know how to create the database like you did. Please help. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

I'm stuck on , I'm using Pycharm and I don't know how to create the database like you did. Please help.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:17:30 - 00:29:58
I am getting an error "ImportError: cannot import name db" while executing from CLI ...  ( minutes)"from flaskblog  import db", can somebody help on how to get this resolved?I rechecked the video and have same code. Still it is failing. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

I am getting an error "ImportError: cannot import name db" while executing from CLI ... ( minutes)"from flaskblog import db", can somebody help on how to get this resolved?I rechecked the video and have same code. Still it is failing.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:17:55 - 00:29:58
Awesome video! Anyone know why at  why I get a 'syntaxError: invalid syntax' on the 'return f"User('{self.username}' ,'{self.email}', '{self.image_file}')"^ - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Awesome video! Anyone know why at why I get a 'syntaxError: invalid syntax' on the 'return f"User('{self.username}' ,'{self.email}', '{self.image_file}')"^

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:17:59 - 00:29:58
On the same note, there was an important caveat he didn't mention at  when he said "That should have created our database".Yes, the database was created, but without any tables. That only happened only after he committed a few lines later. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

On the same note, there was an important caveat he didn't mention at when he said "That should have created our database".Yes, the database was created, but without any tables. That only happened only after he committed a few lines later.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:18:11 - 00:29:58
At  I don't understand the steps to create de site.db file in the same directory. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

At I don't understand the steps to create de site.db file in the same directory.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:18:20 - 00:29:58
Around , for those who are having module error or name error at terminal, please try to write python -m pip install flask_wtf or whatever. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Around , for those who are having module error or name error at terminal, please try to write python -m pip install flask_wtf or whatever.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:18:30 - 00:29:58
checkpoint - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

checkpoint

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:18:40 - 00:29:58
Everything went fine until . when typing in the user_1=... in the terminal I get following error:"sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'Mapper|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." - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Everything went fine until . when typing in the user_1=... in the terminal I get following error:"sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize - can't proceed with initialization of other mappers. Triggering mapper: 'Mapper|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."

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:19:55 - 00:29:58
im getting TypeError: 'email' is an invalid keyword argument for User - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

im getting TypeError: 'email' is an invalid keyword argument for User

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:20:35 - 00:29:58
Hi after db.session.commit, I'm getting an error ofUNIQUE constraint failed: user.image_file[SQL: INSERT INTO user (username, email, image_file, password) VALUES (?, ?, ?, ?)][parameters: ('JohnDoe', 'jd@demo.com', 'default.jpg', 'password')]Please help, Thanks. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Hi after db.session.commit, I'm getting an error ofUNIQUE constraint failed: user.image_file[SQL: INSERT INTO user (username, email, image_file, password) VALUES (?, ?, ?, ?)][parameters: ('JohnDoe', '[email protected]', 'default.jpg', 'password')]Please help, Thanks.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:20 - 00:29:58
on db.session.commit() I got long error. - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

on db.session.commit() I got long error.

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:23 - 00:29:58
If someone manages to mess up at  and now are getting an error do remember to close of the session before trying  again using db.session.close(). - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

If someone manages to mess up at and now are getting an error do remember to close of the session before trying again using db.session.close().

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:25 - 00:29:58
Hi Corey. First, congratulations! High level work. I'm having problems following the steps at . After I added the users 1 and 2 I got an error using db.session.commit(). Any clue what am I doing wrong? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Hi Corey. First, congratulations! High level work. I'm having problems following the steps at . After I added the users 1 and 2 I got an error using db.session.commit(). Any clue what am I doing wrong?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:40 - 00:29:58
At   when I  try to execute the command Usr.query.all() it throws me an error like this - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

At when I try to execute the command Usr.query.all() it throws me an error like this

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:44 - 00:29:58
At  why doesn't it show the password too? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

At why doesn't it show the password too?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:46 - 00:29:58
At minute  I am getting just these:>>> User.query.all() - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

At minute I am getting just these:>>> User.query.all()

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:21:48 - 00:29:58
at  why didn't it show the Password or id columns? - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

at why didn't it show the Password or id columns?

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:22:40 - 00:29:58
Please Help! Error: File "<stdin>", line 1, in <module>AttributeError: 'list' object has no attribute 'id' - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Please Help! Error: File "<stdin>", line 1, in <module>AttributeError: 'list' object has no attribute 'id'

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:24:35 - 00:29:58
i successfully commited the user posts to the database. but when i try to show the posts in the terminal all i got was this response: <sqlalchemy.orm.dynamic.AppenderBaseQuery object at 0x7f51238fcd10>edit: i typed in user_1.postsany idea why?Thanks for the awesome Videos Corey!!!! - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

i successfully commited the user posts to the database. but when i try to show the posts in the terminal all i got was this response: <sqlalchemy.orm.dynamic.AppenderBaseQuery object at 0x7f51238fcd10>edit: i typed in user_1.postsany idea why?Thanks for the awesome Videos Corey!!!!

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:26:20 - 00:29:58
Dude, I am loving this series of videos, but MAN that was a challenging  minutes! Thank you thank you thank you for making this video - Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy

Dude, I am loving this series of videos, but MAN that was a challenging minutes! Thank you thank you thank you for making this video

Python Flask Tutorial: Full-Featured Web App Part 4 - Database with Flask-SQLAlchemy
2018年05月05日 
00:29:57 - 00:29:58

Corey Schafer

※本サイトに掲載されているチャンネル情報や動画情報はYouTube公式のAPIを使って取得・表示しています。

Timetable

動画タイムテーブル

動画数:236件

how to override existing environment variables. (This is new to me) - Python Tutorial: Securely Manage Passwords and API Keys with DotEnv

how to override existing environment variables. (This is new to me)

Python Tutorial: Securely Manage Passwords and API Keys with DotEnv
2024年04月18日  @JorgeEscobarMX 様 
00:10:42 - 00:16:58
the future spoken is my current present. Unless I'm completely desperate, I'm not hitting reddit or google/stack overflow for most roadblocks. - How to Use ChatGPT as a Powerful Tool for Programming

the future spoken is my current present. Unless I'm completely desperate, I'm not hitting reddit or google/stack overflow for most roadblocks.

How to Use ChatGPT as a Powerful Tool for Programming
2023年05月22日  o k t o b e r 様 
00:12:22 - 00:31:08
Good video as always😉  I remember asking that too lol - How to Use ChatGPT as a Powerful Tool for Programming

Good video as always😉 I remember asking that too lol

How to Use ChatGPT as a Powerful Tool for Programming
2023年05月22日  kami 様 
00:28:19 - 00:31:08
@ - pure gold, pure gold! <3 - How to Use ChatGPT as a Powerful Tool for Programming

@ - pure gold, pure gold! <3

How to Use ChatGPT as a Powerful Tool for Programming
2023年05月22日  ulf gjerdingen 様 
00:28:26 - 00:31:08
You almost had me there haha! ChatGPT can be wrong but it certainly wasn't wrong about those top notch resources! I massively appreciate all the uploads and I hope they keep coming supercharged with Chat GPT. Thanks to you, sentdex, techwithtim and Dennis Ivy I now know how to properly code on python, use git for version control and build a functional website. - How to Use ChatGPT as a Powerful Tool for Programming

You almost had me there haha! ChatGPT can be wrong but it certainly wasn't wrong about those top notch resources! I massively appreciate all the uploads and I hope they keep coming supercharged with Chat GPT. Thanks to you, sentdex, techwithtim and Dennis Ivy I now know how to properly code on python, use git for version control and build a functional website.

How to Use ChatGPT as a Powerful Tool for Programming
2023年05月22日  Uj Vag 様 
00:28:42 - 00:31:08
and it's  am here (south east asia), and idk why I'm watching a python tutorial rather than sleeping 😂 - Python Tutorial: Simulate the Powerball Lottery Using Python

and it's am here (south east asia), and idk why I'm watching a python tutorial rather than sleeping 😂

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  X 様 
00:02:49 - 00:38:56
… nice… 😂 - Python Tutorial: Simulate the Powerball Lottery Using Python

… nice… 😂

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  Bartosz Turkowyd 様 
00:04:50 - 00:38:56
I've seen every Python video you've made....   first innuendo. 😜 - Python Tutorial: Simulate the Powerball Lottery Using Python

I've seen every Python video you've made.... first innuendo. 😜

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  Martin Beaudry 様 
00:04:52 - 00:38:56
Man it's  am in India I am lucky to be the first one to hear your voice god bless you brother and an awesome teacher. - Python Tutorial: Simulate the Powerball Lottery Using Python

Man it's am in India I am lucky to be the first one to hear your voice god bless you brother and an awesome teacher.

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  Big Samosa 様 
00:12:15 - 00:38:56
# you can also use the built-in pprint module for pretty printing dictionaries ;) - Python Tutorial: Simulate the Powerball Lottery Using Python

# you can also use the built-in pprint module for pretty printing dictionaries ;)

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  Schoenling Wunderbar 様 
00:25:00 - 00:38:56
it would be very interesting to see if there could be a step function where this algorithm can simulate the increases in jackpot winnings. It’s going to be one in 292+ million of a chance that you hit it at all much less multiple times, but the code should be interesting to see. - Python Tutorial: Simulate the Powerball Lottery Using Python

it would be very interesting to see if there could be a step function where this algorithm can simulate the increases in jackpot winnings. It’s going to be one in 292+ million of a chance that you hit it at all much less multiple times, but the code should be interesting to see.

Python Tutorial: Simulate the Powerball Lottery Using Python
2023年01月10日  20 80 様 
00:27:43 - 00:38:56
A OAuth Django video would be awesome!(Applicable to all sorts of OAuth situations, not just the YouTube API.) - Python YouTube API Tutorial: Using OAuth to Access User Accounts

A OAuth Django video would be awesome!(Applicable to all sorts of OAuth situations, not just the YouTube API.)

Python YouTube API Tutorial: Using OAuth to Access User Accounts
2020年09月10日 
00:07:58 - 00:43:21
At  you move the file and see some blurred miniature version of your open folders in the dock. How did you enable that? - Python YouTube API Tutorial: Using OAuth to Access User Accounts

At you move the file and see some blurred miniature version of your open folders in the dock. How did you enable that?

Python YouTube API Tutorial: Using OAuth to Access User Accounts
2020年09月10日 
00:09:58 - 00:43:21
In case you are getting Error 403 ("access_denied The developer hasn’t given you access to this app") go to the OAuth consent screen and under Test Users add your email by clicking on Add Users.  You should be able to grant access after you've added User. - Python YouTube API Tutorial: Using OAuth to Access User Accounts

In case you are getting Error 403 ("access_denied The developer hasn’t given you access to this app") go to the OAuth consent screen and under Test Users add your email by clicking on Add Users. You should be able to grant access after you've added User.

Python YouTube API Tutorial: Using OAuth to Access User Accounts
2020年09月10日 
00:19:36 - 00:43:21
@corey  So why did you add the join function here, when appending the video id to the list its already a list and its working for me when I pass the vid_ids directly - Python YouTube API Tutorial: Calculating the Duration of a Playlist

@corey So why did you add the join function here, when appending the video id to the list its already a list and its working for me when I pass the vid_ids directly

Python YouTube API Tutorial: Calculating the Duration of a Playlist
2020年06月11日 
00:11:24 - 00:37:38
TypeError: expected string or bytes-like object, I am taking this error in , any idea? - Python YouTube API Tutorial: Calculating the Duration of a Playlist

TypeError: expected string or bytes-like object, I am taking this error in , any idea?

Python YouTube API Tutorial: Calculating the Duration of a Playlist
2020年06月11日 
00:18:50 - 00:37:38
(I love that "Whoops that went too well"-moment at  :D) - Python Tutorial: Real World Example - Using Patreon API and Pillow to Automate Image Creation

(I love that "Whoops that went too well"-moment at :D)

Python Tutorial: Real World Example - Using Patreon API and Pillow to Automate Image Creation
2020年05月11日 
00:35:19 - 00:52:33