0

I am doing a course for my bootcamp in which I am being introduced to sqlAlchemy. I have followed along, restarted 2 or 3 times, and checked every little thing but I cannot get the two to link up. Here are the steps I took:

  • I make a folder
  • Make a venv and activate it
  • Install psycopg, flask-sqlalchemy, ipython
  • Create an app.py file
  • Contents of the file:
from flask import Flask, request, flash, session, redirect, render_template
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)

app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql:///dogs'

db = SQLAlchemy()
db.app = app
db.init_app(app)


app.config['SECRET_KEY'] = 'vdjndv'
  • then I go into ipython, run the file and type db.

The video shows an object returned but all I get is <SQLAlchemy>. I have tried so many different things from other forums and nothing is working. Help is much appreciated as I cannot continue until I figure out this core step.

6
  • "-install psycopg" well that's not going to do much if you don't have an instance of postgres running Commented May 13 at 19:06
  • 1
    Separately, you shouldn't be setting config variables in the script to launch the app. I am suspicious about the tutorial. You would probably be better using this Commented May 13 at 19:08
  • For example, even if you did have the database running, nothing in your code even attempts to talk with it. It might be running, it might not. I strongly suggest dropping whatever tutorial you are watching Commented May 13 at 19:18
  • 1
    1) Most tutorial video's I have seen cause more issues then they solve. 2) This is why good projects have documentation. Go to the source flask-sqlalchemy. 3) The flask-sqlalchemy link will also point you at the SQLAlchemy tutorial. 4) Make your life easier and avoid ORMs, use psycopg(2) directly. Commented May 13 at 23:45
  • 1
    @VincentSchultz then perhaps you do have a postgres server running in the background; like I said, it's not possible to tell from the code as it is. Also, you are incorrect; this is not simple stuff so you shouldn't feel bad for being confused. You're talking about multiple systems that need to communicate. This is why I really suggest using the tutorial I linked, at least as an aside to your bootcamp if you don't want to drop that. You might even be able to find the flaws in the tutorial yourself as you progress :) Commented May 14 at 10:37

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.