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

  Рет қаралды 675,394

Corey Schafer

Corey Schafer

Күн бұрын

Пікірлер: 1 000
@danielwarzecha2007
@danielwarzecha2007 Жыл бұрын
Hey All: As of version SQLAlchemy 3.0 to create your db file you will need to run some commands like this in the shell : from project import app, db app.app_context().push() db.create_all() Then the .db file is created in a folder called "Instance" in your project. Hope this helps some one
@MykhailoRogozhyn
@MykhailoRogozhyn Жыл бұрын
Thank you very much. It really helps me.
@MattFussell
@MattFussell Жыл бұрын
I was able to get the database created, but none of the follow-up steps worked for me. I'm sure given enough time I could find a fix, but I'm short on it, so I'm hoping it works well enough for rest of the tutorial.
@MykhailoRogozhyn
@MykhailoRogozhyn Жыл бұрын
@@MattFussell Everything else works as in the video. But I don't really like that the database is stored in the Instance directory. I changed the path to the database file as described in Miguel Grinberg's book. import os basedir = os.path.abspath(os.path.dirname(__file__)) app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'site.db') Maybe it will be useful for others.
@harshitpathak5958
@harshitpathak5958 Жыл бұрын
I somehow managed to create this site.db but now , 1- I couldn't able to run any other command for entering the users in command prompt (getting same out of context error) 2 - if adding the user within our with app.app_context(): db.create_all() user 1= details..... db.session.add(user1) By doins so I am still getting a integrity error for email , even its unique
@MattFussell
@MattFussell Жыл бұрын
@@harshitpathak5958 My DB knowledge is thin, so apply the appropriate amount of salt. It sounds like you may have an error in your ORM code - like the field has been set to expect one thing and receiving something else.
@othmanethebold9004
@othmanethebold9004 2 жыл бұрын
For anyone who is facing the error of 'outside application context', try this : - in your terminal: from import app, db - with app.app_context(): db.create_all() Note: You can use this also when you will want to add data to the database. GoodLuck!
@mikevogt71
@mikevogt71 2 жыл бұрын
Oh wow! You saved me! I have been stuck for days with this error and was ready to throw out the entire tutorial. I owe you a beer! Thanks VERY MUCH!
@mikevogt71
@mikevogt71 2 жыл бұрын
Well - while this gets me beyond the immediate 'application context' error, it takes me off the path shown in Corey's video. I am planning on abandoning this series in favor of a more up to date offering. Thank you for your insight.
@othmanethebold9004
@othmanethebold9004 2 жыл бұрын
@@mikevogt71 These bugs really blow one's mind lol but they should never be a roadblock, just keep trying, you will learn alot!
@aliyanpops6424
@aliyanpops6424 Жыл бұрын
Thnks for killing the fustration
@sarahcruz7352
@sarahcruz7352 Жыл бұрын
Thank you for posting this
@soumyajitdey5720
@soumyajitdey5720 4 жыл бұрын
Corey Schafer is teaching us things which we did not learn in universities. I promise I will support you through Patreon once I land a job.
@coreyms
@coreyms 4 жыл бұрын
Thanks! Glad you found the videos helpful!
@bisthenickel
@bisthenickel 4 жыл бұрын
Me too!
@hananjamal2431
@hananjamal2431 3 жыл бұрын
I will too
@Akshay-cj3hq
@Akshay-cj3hq 3 жыл бұрын
Did you land a job yet?
@MichaelTheSaffa
@MichaelTheSaffa 2 жыл бұрын
my uni is teaching me this
@meenamotiramani5244
@meenamotiramani5244 4 жыл бұрын
Behind the smooth voice is tons of debugging and eternities of reading the docs
@brawlmania7544
@brawlmania7544 3 жыл бұрын
Most of which is trying to find the 1 damnable parenthesis or quotes
@CainanParker
@CainanParker 5 жыл бұрын
17:04 made me so happy when you noticed that and fixed it. I had a solid 10 minutes of anxiety.
@zainbaloch5541
@zainbaloch5541 5 жыл бұрын
yeah, I was waiting for him to realize it, though I did it right in the first place ;)
@a69e87
@a69e87 4 жыл бұрын
lol
@padraic1983
@padraic1983 3 жыл бұрын
Hey Corey, you literally helped me Land a dream job . Thank you for all you've contributed.
@sirnakerb209
@sirnakerb209 6 жыл бұрын
Your videos are really great! Every second of this video is understandable, that really takes talent! Keep it up!
@jartavia05
@jartavia05 6 жыл бұрын
Im completely agree. Great Videos.
@giuseppetemisio1158
@giuseppetemisio1158 6 жыл бұрын
In my university I'm attending a course of Information System in which the professor is using exactly your code in the labs lessons without mentioning you. I found you by looking for help on youtube.
@andreasmiles6066
@andreasmiles6066 6 жыл бұрын
Hey GT, do yo mind me asking which uni do you study at and which course? Thanks.
@sagarthakore
@sagarthakore 5 жыл бұрын
@@X............................. Your display picture made me scratch my monitor screen! Felt like a fool when I realized it was just your picture. This is pure evil genius!
@rancoxu
@rancoxu 5 жыл бұрын
University of Queensland?
@rulo1894
@rulo1894 5 жыл бұрын
If I am right you study at Università degli Studi di Napoli Federico II jajaja. Also love the number of likes in your comment!
@irishRocker1
@irishRocker1 5 жыл бұрын
​@@matthewbotti That is a pretty naive view of things. I have learned lots from youtube and google in general but i still would not trade in my college education. There are things college cant teach you or give real world experience in but it does set you up well for "learning how to learn" and developing your career. It helps create the foundation that you will build upon for the rest of your career. Just learning from youtube will teach you some things but it doesn't quite give you the solid foundation that college will or as good an understanding. I studied electronic engineering (which includes programming) and I read some hobbyist forums sometimes where people have learned stuff themselves but they also lack some pretty important knowledge and understanding. It usually takes the handful of talented guys on those forums to bring up the level of everyone else who still have to ask simple questions or to correct some opinions that are not accurate etc. Same for places like stack overflow. people asking basic questions because they learned something online but they hit one bump on the road and don't have the background/understanding to figure it out themselves and have to go ask online and wait for someone else to solve it for them. And for the record, in Europe we pay far less for college education than say the USA. €1500 a year is what i paid and had no debt after it.
@fouroakfarm
@fouroakfarm 6 жыл бұрын
As someone who wrote PHP 20 years ago, damn do I wish this existed then haha This is awesome. Thanks for your incredibly clear and concise videos
@stormerthe2nd
@stormerthe2nd 5 жыл бұрын
While True: Print("Thank You So Much")
@BurgerBurglar8964
@BurgerBurglar8964 4 жыл бұрын
Do keep in mind that Python is case sensitive!
@riddhiman2926
@riddhiman2926 4 жыл бұрын
Traceback (most recent call last): File "", line 1, in NameError: name 'Print' is not defined
@BurgerBurglar8964
@BurgerBurglar8964 4 жыл бұрын
Riddhiman 36 I'm pretty sure While isn't a keyword and this will fail on the first line
@sansovino4124
@sansovino4124 4 жыл бұрын
@@BurgerBurglar8964 'while' is a valid keyword. Should read: while True: print("Thank You So Much") God we're pedantic aren't we!
@liubohan7008
@liubohan7008 4 жыл бұрын
I think auto-correction is the culprit to blame here hhh
@ArchAid1
@ArchAid1 6 жыл бұрын
Dude, I am loving this series of videos, but MAN that was a challenging 29:57 minutes! Thank you thank you thank you for making this video
@irishRocker1
@irishRocker1 5 жыл бұрын
I watch at 2x speed.
@mihirshrestha6652
@mihirshrestha6652 4 жыл бұрын
@@irishRocker1 No one asked
@mahtoosacks
@mahtoosacks 5 жыл бұрын
Ive been playing with laravel for several months, but after seeing how clean and simple flask is, I'm probably going to jump onto python. Thank you for this amazing reference
@mckadesorensen2539
@mckadesorensen2539 5 жыл бұрын
When I'm no longer a broke college student I'll be joining your Patreon!!
@coreyms
@coreyms 5 жыл бұрын
Thanks!
@tubalix
@tubalix 5 жыл бұрын
One of the clearest, most understandable and easy to follow instructional videos on the topic. Much much better than 99.9% (OK, I could have written 100%....) of what I have seen around.
@treelight1707
@treelight1707 6 жыл бұрын
This may be the best crash course on sqlalchemy. Love the series.
@TRasheed94
@TRasheed94 3 жыл бұрын
From watching your videos and reading these comments, I no longer regret not studying a computer science degree at university :)
@kavabangaungava
@kavabangaungava 6 жыл бұрын
Many thanks from Russia. Your educational videos are great.
@brentelisens9163
@brentelisens9163 5 жыл бұрын
the best flask tutorial series hands down. i don't even mind the ads and i've had monstrous urges to break screens over them.
@irishRocker1
@irishRocker1 5 жыл бұрын
ah, reading comments like these makes me glad i subscribed for youtube premium lol adverts used to wreck my head!
@brentelisens9163
@brentelisens9163 5 жыл бұрын
@@irishRocker1 it's free knowledge. his presentation is in depth and easy to follow. you paid for a free service because you didn't want to wait 5 whole seconds.
@roosterglobal2648
@roosterglobal2648 5 жыл бұрын
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!
@kanishkasah4383
@kanishkasah4383 8 ай бұрын
23:44 "user = User.query.get(1)" while running this query ... :1: LegacyAPIWarning: The Query.get() method is considered legacy as of the 1.x series of SQLAlchemy and becomes a legacy construct in 2.0. The method is now available as Session.get() (deprecated since: 2.0) The warning you're seeing is indicating that the Query.get() method is considered legacy in SQLAlchemy and will be deprecated in version 2.0. Instead, it suggests using the Session.get() method. solution- "user = db.session.get(User, 1)"
@drozdekPty
@drozdekPty 5 жыл бұрын
Have been doing coding since 15 years, but this is one of the best videos have seen so far. Respect!
@tomasemilio
@tomasemilio 5 жыл бұрын
bro. genius , love the way you teach. on vacation actually, pumped to learn here at a cafe in the middle of patagonia. keep it up
@coreyms
@coreyms 5 жыл бұрын
Whoa, that sounds like an awesome vacation!
@clippysnips
@clippysnips 3 жыл бұрын
Hi Corey! First off, I want to say thank you for all of these comprehensive tutorials that you shared with us! I really appreciate all the work that you've done on your channel! With regards to my concern, I was wondering what steps I should take when converting from an SQLite database to a PostgreSQL one. Hope you could enlighten me on this one. Thank you again very much!
@Manuel-rl6um
@Manuel-rl6um 5 жыл бұрын
If db.create_all() is not creating the file for you, check that you wrote URI and not URL in "app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db'". Don't be me xD Following this tutorial in WLS2 but in my Windows 10's VS Code accessing Ubuntu remotely. Working perfectly so far. To set up VS Code of Windows 10 to work with your Ubuntu WLS, following this: code.visualstudio.com/remote-tutorials/wsl/getting-started Amazing tutorial so far!
@elecmn
@elecmn 6 жыл бұрын
by the way Corey you are the best tutor ever on youtube
@bhoomeendra
@bhoomeendra 6 жыл бұрын
This is my first time with database and it is really simple because of you thanks again
@irmscher9
@irmscher9 6 жыл бұрын
Wow, you are starting super fast in this video, I first though my video is set on 1.25 speed :). Thanks a lot for your tutorials by the way!
@tradewinds9832
@tradewinds9832 4 жыл бұрын
OMG, this is one of the best tutorials that I have found on YT. I'll see what I can to help.
@mahyarazad
@mahyarazad 4 жыл бұрын
You are the best teacher ever I had. many thanks to you, I can now connect the dots and, understand how do these libraries work together. Respect.
@meqsed-novruzov-92
@meqsed-novruzov-92 5 жыл бұрын
I love this guy's tutorial series.
@mjj2u2
@mjj2u2 2 жыл бұрын
Exceptional video. Your examples are on point and flow very well. I find you explanations clear and very concise. They explain everything I need to know with out rambling. Any questions that came to my mind were answered in the video. (Get out of my mind you freaking mind reader! Ha ha) All technical videos should take a note from how this was made. Well done, and thank you. I'm sure a lot of hard work and forethought went into this.
@Rafiki041087
@Rafiki041087 6 жыл бұрын
Really like the quality of these videos. Great tutorial. Took some time to wrap my head around the datetime.utcnow part and why it should be without the (), especially after creating post1 in the terminal and the datetime was Null. But after running the .add(post1) and the .commit() it all made sense.
@sonny8595
@sonny8595 5 жыл бұрын
Could you explain it to us?
@silverzero9524
@silverzero9524 4 жыл бұрын
@@sonny8595 if u do datetime.utcnow() then the function will get executed and will return a DateTime and that returned value will be assigned as default we dont want that we want get current datetime everytime
@prkprime
@prkprime 4 жыл бұрын
this is the most detailed tutorial i have ever seen i'm watching every video in this tutorial
@derrickakomeah
@derrickakomeah 4 жыл бұрын
Dude you are so talented and know how to commincate Your videos are the best thank you so much
@vishupal8982
@vishupal8982 4 жыл бұрын
It is the best video than my udemy courses I learn a lot form your video Thanks a lot sir continue your series..
@marc-olivierblouin4709
@marc-olivierblouin4709 6 жыл бұрын
Will you make a tutorial for switching SQLAlchemy database to production one? Thanks!!
@chetna.gorawala
@chetna.gorawala 2 жыл бұрын
Couldn't find a better teacher and programmer> Amazing teaching techniques. Thank You Corey
@mu9344
@mu9344 4 жыл бұрын
Around 18:30, for those who are having module error or name error at terminal, please try to write python -m pip install flask_wtf or whatever.
@investandcyclecheap4890
@investandcyclecheap4890 2 жыл бұрын
thank you ! This saved me so much time !
@roodrums
@roodrums 2 жыл бұрын
if that doesn't work just use every different type of pip install e.g. python3-m pip install .... pip3 install ...... should work
@xxXNMEXxx
@xxXNMEXxx Жыл бұрын
thanks!!!
@I_am_pradeep
@I_am_pradeep 6 жыл бұрын
The quality of the content is so good. It's so understandable and useful.
@EnesKab
@EnesKab 5 жыл бұрын
If you are getting error while creating new user, you can try to change lazy="True" to lazy="dynamic" I had to spend 2 hours, before i figure it out.
@lipcioful
@lipcioful 5 жыл бұрын
Omg, thanks for sharing that with us! It threw "sqlalchemy.exc.InvalidRequestError: One or more mappers failed to initialize" and answers on the web were very confusing, this one did the job!
@ahmedjalal9518
@ahmedjalal9518 4 жыл бұрын
@@lipcioful man you saved me .You wasted 2hours but i waste 4hours solving this one. Thanks!
@r.h.5172
@r.h.5172 4 жыл бұрын
I changed lazy="True" to lazy="dynamic" still I am getting this error
@joellekamaha2600
@joellekamaha2600 4 жыл бұрын
Thanks for the tweak
@joellekamaha2600
@joellekamaha2600 4 жыл бұрын
@@r.h.5172 save the work and in the python shell import the tables again `from flaskblog import User, Post` before creating the user.
@johnphilipangeles1825
@johnphilipangeles1825 4 жыл бұрын
Thanks Corey! Really helpful as I'm trying to finish up my first web app in Flask.
@ykangho
@ykangho 5 жыл бұрын
Thank you so much, your teaching is clear and easy to understand! It helps me a lot.
@sachavanweeren9578
@sachavanweeren9578 3 жыл бұрын
Thanks for this great video. Tried to code along with the similar tutorial from Flask itself but that one is difficult to understand. Here you break it up in nice pieces and use much more intuitive coding. Thank you very much....
@dsdgaming2242
@dsdgaming2242 6 жыл бұрын
Hello Corey, please include a tutorial for making a Many-to-Many relationship in Flask-SQLAlchemy. Thanks
@ibrahimoluwajobaadisa392
@ibrahimoluwajobaadisa392 2 жыл бұрын
Thank you Corey. You cover all that is necessary within reasonable time yet in details.
@hrishikeshmahajan752
@hrishikeshmahajan752 4 жыл бұрын
If someone manages to mess up at 21:25 and now are getting an error do remember to close of the session before trying again using db.session.close().
@0xLoneWolf
@0xLoneWolf 4 жыл бұрын
Thank you for that. Idk what fixed my "SQLite objects created in a thread can only be used in that same thread." issue but this may have been it!
@ukuleleguy16cs36
@ukuleleguy16cs36 4 жыл бұрын
Good teacher... Your teaching style is amazing. Each and every line is clearer and to the point..
@44_Leaf_Clover
@44_Leaf_Clover 5 жыл бұрын
Great series Corey, I'm recommending your channel to everyone I meet! To anyone getting an error: sqlalchemy.exc.NoSuchModuleError: Can't load plugin: sqlalchemy.dialects.sqllite when running $ db.create_all() - I solved this by pip installing an earlier version of SQLAlchemy (1.2.7) [my previous version was 1.2.16] and this solved the problem. Thought it might help someone.
@Brogun420
@Brogun420 4 жыл бұрын
you did sqllite not sqlite in app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///site.db' (i did the same thing :-/)
@jatin1688
@jatin1688 3 жыл бұрын
Amazing , superb and best video of flask python in whole internet , KZbin and all
@mudassiraqeel8604
@mudassiraqeel8604 2 жыл бұрын
I'm getting this error, when I try to run db.create_all() in terminal: RuntimeError: Working outside of application context. This typically means that you attempted to use functionality that needed the current application. To solve this, set up an application context with app.app_context(). See the documentation for more information.
@sanjayjain3139
@sanjayjain3139 2 жыл бұрын
i am stucked here from 2 days
@harshbhandari5549
@harshbhandari5549 Жыл бұрын
You have to manually set the context- >>> from project import app, db >>> app.app_context().push() >>> db.create_all()
@kenimprov
@kenimprov 9 ай бұрын
@handari5549 Why didn't Corey have to do this? Is it because of a difference in versions? Edit. seems like I needed to add db.init_app(app) after the line db=SQLAlchemy()
@luke2306
@luke2306 Жыл бұрын
This video really helped me a lot, everything is clear now tysm Corey !
@monishagowda8928
@monishagowda8928 6 жыл бұрын
Thank you sooo much for the tutorials!! It helped me big time for my project. You teach way better than my teachers.
@prashantjeena4629
@prashantjeena4629 5 жыл бұрын
what project did you make ?....i'm a beginner and need to make a project ..can you please guide me a little?
@davidboatengadams301
@davidboatengadams301 5 жыл бұрын
i get errors with this line of code, db.Column(db.String(60), nullable=False) it says " Instance of 'SQLAlchemy' has no 'Column' member"
@lieuich6184
@lieuich6184 5 жыл бұрын
i got the same problem as you so this is what I did, hopefully, it will work for you 1.pip install pylint-flask 2Load the installed plugin. For example, if you use VS code, please edit setting.json file as follows: (opened with the File > Preferences > Settings command ⌘, search for settings.json and one of the options will let you edit it) add this line "python.linting.pylintArgs": ["--load-plugins", "pylint_flask"]
@Jay-pm6vk
@Jay-pm6vk 4 жыл бұрын
@@lieuich6184 Thank you very much!
@MarcusReaiche
@MarcusReaiche 4 жыл бұрын
Hello, I just wanna add some remarks. I had the same problem, but for me the solution was to install the pylint_flask_sqlalchemy additionally to the pylint_flask plugin. This post (pypi.org/project/pylint-flask-sqlalchemy/) shows all the steps including the load of the plugin through the command line. For someone that uses VSCode, it is worth pointing that one should add the following lines to the .pylintrc file: load-plugins=pylint_flask,pylint_flask_sqlalchemy Hope that this can be useful for somebody!
@goldymazumdar9741
@goldymazumdar9741 4 жыл бұрын
How to resolve this problem in Pycharm ??
@25kirtan
@25kirtan 4 жыл бұрын
@@lieuich6184 Hey this doesn't seem to help. Any other fixes?
@pengtroll6247
@pengtroll6247 4 жыл бұрын
This was by far the best tutorial on integrating sqlalchemy with python! thanks man!!
@AdityaFingerstyle
@AdityaFingerstyle 5 жыл бұрын
To make that sqlalchemy warning disappear add this app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
@ted9097
@ted9097 4 жыл бұрын
This is a step above a lot of videos in terms of DB set up. Nice work!
@takundamafuta7355
@takundamafuta7355 4 жыл бұрын
I'm stuck on 17:30, I'm using Pycharm and I don't know how to create the database like you did. Please help.
@himanshusingh3219
@himanshusingh3219 4 жыл бұрын
@Squishy Chilli im also using pycharm and getting some error while using terminal
@programming_hut
@programming_hut 4 жыл бұрын
you are simple best and you provide high quality education for free ❤️❤️ thanks a lot 🙏
@heisenburgfreed7591
@heisenburgfreed7591 4 жыл бұрын
The command to install Flask-SQLAlchemy in the video is out of date now, please use below instead: pip install -U Flask-SQLAlchemy
@keshavbansal5148
@keshavbansal5148 3 жыл бұрын
Both the commands work just fine.
@PythonDevelopment
@PythonDevelopment 3 жыл бұрын
@@keshavbansal5148 no, first command don't working more
@ase713
@ase713 3 жыл бұрын
@@PythonDevelopment if you follow the requirements file, you will find that it does work fine'
@ayomaluh452
@ayomaluh452 2 жыл бұрын
for anyone whose having an issue with db.create_all(), use the following commands after watching the next video. (env) C:.\..\..\flask app\Flask_blog>set FLASK_APP=run (env) C:.\..\..\flask app\Flask_blog>flask shell >>> from flaskblog import db >>> from flaskblog.models import User, Post >>>db.create_all()
@gunnarpope
@gunnarpope 5 жыл бұрын
Dude, your videos are so good! Very high quality and helpful. Thanks!
@Prelude2ADream
@Prelude2ADream 6 жыл бұрын
If you use the filter_by function with say username='Corey' and you had users with usernames Corey and say CoreyS, would it pick up both of them or only the exact match Corey? Thanks for a great video!
@shakiestnerd
@shakiestnerd 5 жыл бұрын
filter_by() is going to return an exact match. If there are more than one username='Corey', User.query.filter_by(username='Corey').all() would return all of them. On the other hand, if you wanted all of the variants, you could use something like User.query.filter(User.username.like == '%Corey%')).all(). This would return a list of all the username that contained the string 'Corey'. Love the question --- you made my look up the answer!
@glensworld66
@glensworld66 6 жыл бұрын
Love this series (and have watched several of your others, including the learning python series). Thanks! Wish you would have discussed indexes and when and how you use them. Thanks again!
@parvazprint1009
@parvazprint1009 5 жыл бұрын
hey there hows it going everybody
@untildawn5714
@untildawn5714 6 жыл бұрын
Hi @Corey! Thank for the series I had some headache until I found your videos to resolve my little issues :D Thanks !
@divyeshtharakan513
@divyeshtharakan513 4 жыл бұрын
Hi there, I encountered an error which says cannot import Flask from flask while importing db from flaskblog. Please help
@ihebhaboubi1570
@ihebhaboubi1570 5 жыл бұрын
Thank you so much Corey , Your Videos have taught me a lot about python and Web development, You are amazing!
@pranshuagrawal8046
@pranshuagrawal8046 4 жыл бұрын
Sir its showing error when I am trying to import User, Post from flaskblog, saying : ImportError: cannot import name 'User' from 'flaskblog'
@SandipPoddar
@SandipPoddar 4 жыл бұрын
Check spelling of User or your main file name
@pururaj6566
@pururaj6566 4 жыл бұрын
A universities never teach us these you are greate.
@paulcal3500
@paulcal3500 2 жыл бұрын
I am getting an error when I try to db.create_all(). The error is: "RuntimeError: Working outside of application context". This even happens when I try to run the source code. Any idea why?
@weedwackerfannypacker
@weedwackerfannypacker 2 жыл бұрын
i have been stuck on this for a while too did you figure it out?
@paulcal3500
@paulcal3500 2 жыл бұрын
@@weedwackerfannypacker Nope. Don't understand any of the explanations online. You?
@janmurin6834
@janmurin6834 3 жыл бұрын
Best flask tutorial i have seen. helped me start my own projects. I Have a question however, if you can show how to do many to many relationship that would be helpfull.
@antongirdeux4148
@antongirdeux4148 6 жыл бұрын
Hey, Corey I got this error: [pylint] E1101:Instance of 'SQLAlchemy' has no 'Column' member How do I fix it? Thank you.
@johnathaningle8855
@johnathaningle8855 5 жыл бұрын
Its an error within the python linter. If you are using VScode (like me) it shows an error in the editor but runs correctly
@joerothstein8101
@joerothstein8101 5 жыл бұрын
@@johnathaningle8855 I'm also running VSCode, and see the same error.
@esaadlb
@esaadlb 5 жыл бұрын
pip install flake8
@azizbohra6666
@azizbohra6666 4 жыл бұрын
@@johnathaningle8855 Disable Linter (pylint)
@azizbohra6666
@azizbohra6666 4 жыл бұрын
@@ElmerGLue Disable the Linter (pylint)
@АртурРожков-в8ф
@АртурРожков-в8ф 5 жыл бұрын
Thank you, mr Corey Schafer!
@puravida77700
@puravida77700 6 жыл бұрын
Wonderful tutorial, thanks alot! Everything went fine until 19:55. 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." Also when typing in db.create_all() following error occurs: "sqlalchemy.exc.NoReferencedTableError: Foreign key associated with column 'post.user_id' could not find table 'user_id' with which to generate a foreign key to target column 'None'" I have copied the code straight from Corey github just to be sure... Any idea as to why this is happening?
@scarmusic90
@scarmusic90 5 жыл бұрын
flask-sqlalchemy.palletsprojects.com/en/2.x/quickstart/ - this helped me out. make a quests user and then create the user_1 - mine worked all of a sudden.
@WanhedaPY
@WanhedaPY 4 жыл бұрын
1 year after lol but yeah I got this too, fixed it when I put my Posts class above my User class. Also the second thing about can’t find user_id table, the foreign key is “user.id” not “user_id”
@josbexerr5166
@josbexerr5166 4 жыл бұрын
Simplemente excelente tutorial grascias Mister Corey
@forithall2417
@forithall2417 6 жыл бұрын
I can't use db.Column, in the "class User(db.Model)" it says >>>>>>>> [pylint] E1101:Instance of 'SQLAlchemy' has no 'Column' member HELP!!!!!!!!!!!
@brankokuridza8386
@brankokuridza8386 6 жыл бұрын
For me this worked : pip install pylint --upgrade
@ritheshjarvis4177
@ritheshjarvis4177 4 жыл бұрын
best Python Guru
@guntarget
@guntarget 4 жыл бұрын
There appears to be a recent update to werkzeug that prevents the command from flaskblog import db from working (kzbin.info/www/bejne/mYq6mneffrqrh8Um46s). pip install werkzeug==0.16.0 seems to fix it. see github.com/scoringengine/scoringengine/issues/670
@gideonyektai3414
@gideonyektai3414 4 жыл бұрын
Yes! Thank you for the solution this is exactly what I was searching for. Is this a problem from the first pip installs not covering this, or was something changed in an update?
@rodhash
@rodhash 3 жыл бұрын
Sir you have sick teaching skills, omg .. I'll definetly become a patreon
@tusharguliany3633
@tusharguliany3633 6 жыл бұрын
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: When initializing mapper Mapper|User|user, expression 'Post' failed to locate a name ("name 'Post' is not defined"). If this is a class name, consider adding this relationship() to the class after both dependent classes have been defined. All that I did different was to change blogpost.py to app.py Can You Please Help ?
@inztomoe2530
@inztomoe2530 6 жыл бұрын
i had the same problem. turned out i misspeling word 'ForeignKey'. after i corected it, i reopen project and it start working.
@reggiemate7288
@reggiemate7288 6 жыл бұрын
It is probably too late, but I ran into the same error. I had a couple of spelling errors. However as you edit you will get the same errors over and over again. You may have also entered the python commands in wrong into the terminal. Best option is create a new instance of the terminal. Then re enter all the commands. THis worked for me. from flaskblog import db db.create_all() from flaskblog import User, Post user_1 = User(username='Test', email='t@t.com', password='p') db.session.add(user_1)
@saidkarimsaidmahmudov3048
@saidkarimsaidmahmudov3048 6 жыл бұрын
sqlalchemy.exc.InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (sqlite3.IntegrityError) UNIQUE constraint failed: user.email [SQL: 'INSERT INTO user (username, email, image_file, password) VALUES (?, ?, ?, ?)'] [parameters: ('Corey', 'C@demo.com', 'default.jpg', 'password')] (Background on this error at: sqlalche.me/e/gkpj)
@stephenosei-bonsu625
@stephenosei-bonsu625 6 жыл бұрын
I also had this problem. it got me stuck a whole day
@vijaysinghrajput8526
@vijaysinghrajput8526 6 жыл бұрын
FOR THOSE...WHOSE SQLALCHEMY IS NOT WORKING....USE MOGODB AND PYTHON MODULE [FLASK-PYMONGO]
@christoph3333
@christoph3333 6 жыл бұрын
Amazing tutorial. Everything is explained clearly and easy to follow.
@lucianpirjol8526
@lucianpirjol8526 3 жыл бұрын
Hello, can anyone help me with this error? : Traceback (most recent call last): File "C:/Users/lucia/PycharmProjects/Flask_blog/flaskblog.py", line 13, in class User(db.Model): File "C:/Users/lucia/PycharmProjects/Flask_blog/flaskblog.py", line 14, in User id = db.Column(db.Integer, primary_key=True) TypeError: Column() got an unexpected keyword argument 'primary_key' Process finished with exit code 1 Thank you !
@aashayshah1120
@aashayshah1120 3 жыл бұрын
Save your files, close your command prompt and restart it. It worked for me !
@Sp20100
@Sp20100 4 жыл бұрын
Thanks for this course videos, you're amazing at teaching
@ahmedyousif4782
@ahmedyousif4782 3 жыл бұрын
fun fact: you are in the comment section because db.create_all() didn't work
@SuperChristianMiiworld
@SuperChristianMiiworld 3 жыл бұрын
also fun fact: we care about the solution, not some lame joke
@epic_waffle2359
@epic_waffle2359 4 жыл бұрын
YOU DESERVE 1 MILLION SUBS!
@bartox-tt4pg
@bartox-tt4pg 5 жыл бұрын
In my opinion Peewee is more clear and understandable, but SQLA is nice too. Thanks for all of yours tuts
@charles7483
@charles7483 4 жыл бұрын
I will support you as well after I get the job!
@manhngo2724
@manhngo2724 4 жыл бұрын
Thank you very much, your video helps me a lot.
@FanofScandal
@FanofScandal 4 жыл бұрын
thanks this is an awesome tutorial. good to follow, good explaination. and the biggest point is the free source code to look back at. for reference if i am walking to an unexpected error. so thanks a lott. you helping me a lot with this tutorial
@sebastianskopek
@sebastianskopek 4 жыл бұрын
am i the only one who watches a 30min video in over an hour (coding included) ? :)
@imanhosseinipour3650
@imanhosseinipour3650 5 жыл бұрын
Your videos are really great ! Thanks for every things
@Felipe-53
@Felipe-53 4 жыл бұрын
Man, thank you so much. You are the best. Hope you are doing well!
@nextoo1
@nextoo1 6 жыл бұрын
This guy is incredible.. bloody hell!.
@GiangPham-zj3pv
@GiangPham-zj3pv 4 жыл бұрын
thank you so so much for the videos! they were so helpful to navigate Python Flask :)
@patriotlightning7791
@patriotlightning7791 6 жыл бұрын
Excellent tutorials mate.
@HenokGashaw
@HenokGashaw 4 жыл бұрын
17:05 😁 ,,, Great tutorial - Easily understandable - Thank you Very much
@FactDesk
@FactDesk 4 жыл бұрын
ur my mentor man , tq corey
@Shubham16ify
@Shubham16ify 2 жыл бұрын
One very basic question..related to the python about this lecture...why we mostly use class attributes in python while accessing DB? Example why we didnt use self.username or self.id , etc here and used. Example: class User(db.Model): id=db.Column(db.Integer, primary_key=True) username=db.Column(db.String(20), unique=True, nullable=False) email=db.Column(db.String(120), unique=True, nullable=False)
@FranVarVar
@FranVarVar 5 жыл бұрын
Excellent as always Corey. I would love to see a video about db migrations now. Thanks!
@yasinfrough
@yasinfrough Жыл бұрын
Thank you so much these amazing explanations.
One day.. 🙌
00:33
Celine Dept
Рет қаралды 66 МЛН
SIZE DOESN’T MATTER @benjaminjiujitsu
00:46
Natan por Aí
Рет қаралды 8 МЛН
How To Choose Mac N Cheese Date Night.. 🧀
00:58
Jojo Sim
Рет қаралды 115 МЛН
Чистка воды совком от денег
00:32
FD Vasya
Рет қаралды 5 МЛН
SQLAlchemy Turns Python Objects Into Database Entries
22:23
NeuralNine
Рет қаралды 183 М.
SQLModel + FastAPI: Say Goodbye to Repetitive Database Code
19:50
Databases & SQLAlchemy - Flask Tutorial Series #7
33:58
NeuralNine
Рет қаралды 18 М.
build a meme Python website (Flask Tutorial for Beginners)
13:30
NetworkChuck
Рет қаралды 514 М.
SQLAlchemy Makes Using Python Databases EASY
19:08
Eric Roby
Рет қаралды 5 М.
One day.. 🙌
00:33
Celine Dept
Рет қаралды 66 МЛН