Python Forum
SQL Alchemy, database does not work
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SQL Alchemy, database does not work
#1
Hallowings,

I am trying to make my very first database app according to this tutorial - https://www.youtube.com/watch?v=0FsvqwRh...HV&index=7

The Python code is

from flask import Flask, render_template, request, redirect, url_for
from flask_sqlalchemy import SQLAlchemy


app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://sql11200793:[email protected]/sql11200793'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

db = SQLAlchemy(app)

class Comments(db.Model):
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(20))
	comment = db.Column(db.String(1000))

@app.route('/')
def index():
	result = Comments.query.all()

	return render_template('index.html', result=result)

@app.route('/sign')
def sign():
	return render_template('sign.html')

@app.route('/process', methods=['POST'])
def process():
	name = request.form['name']
	comment = request.form['comment']

	signature = Comments(name=name, comment=comment)
	db.session.add(signature)
	db.session.commit()

	return redirect(url_for('index'))

@app.route('/home', methods=['GET', 'POST'])
def home():
	links = ['https://www.youtube.com', 'https://www.bing.com', 'https://www.python.org', 'https://www.enkato.com']
	return render_template('example.html', links=links)

if __name__ == '__main__':
	app.run(debug=True)
(I don't think HTML's templates would hold anything interesting....)

and it does not work: When I hit run it PyCharm says it's ready on 127.0.... but when I go there I get error :

File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1997, in __call__
return self.wsgi_app(environ, start_response)
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1985, in wsgi_app
response = self.handle_exception(e)
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1540, in handle_exception
reraise(exc_type, exc_value, tb)
File "C:\Language\Python3.6\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1982, in wsgi_app
response = self.full_dispatch_request()
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
rv = self.handle_user_exception(e)
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "C:\Language\Python3.6\lib\site-packages\flask\_compat.py", line 33, in reraise
raise value
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
rv = self.dispatch_request()
File "C:\Language\Python3.6\lib\site-packages\flask\app.py", line 1598, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "C:\temp\example1\venv\app\IntroToFlask.py", line 18, in index
result = Comments.query.all()
File "C:\Language\Python3.6\lib\site-packages\flask_sqlalchemy\__init__.py", line 514, in __get__
return type.query_class(mapper, session=self.sa.session())
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\orm\scoping.py", line 78, in __call__
return self.registry()
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\util\_collections.py", line 990, in __call__
return self.registry.setdefault(key, self.createfunc())
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\orm\session.py", line 2867, in __call__
return self.class_(**local_kw)
File "C:\Language\Python3.6\lib\site-packages\flask_sqlalchemy\__init__.py", line 143, in __init__
bind = options.pop('bind', None) or db.engine
File "C:\Language\Python3.6\lib\site-packages\flask_sqlalchemy\__init__.py", line 877, in engine
return self.get_engine()
File "C:\Language\Python3.6\lib\site-packages\flask_sqlalchemy\__init__.py", line 896, in get_engine
Open an interactive python shell in this framereturn connector.get_engine()
File "C:\Language\Python3.6\lib\site-packages\flask_sqlalchemy\__init__.py", line 559, in get_engine
self._engine = rv = sqlalchemy.create_engine(info, **options)
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\engine\__init__.py", line 391, in create_engine
return strategy.create(*args, **kwargs)
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\engine\strategies.py", line 80, in create
dbapi = dialect_cls.dbapi(**dbapi_args)
File "C:\Language\Python3.6\lib\site-packages\sqlalchemy\dialects\mysql\mysqldb.py", line 110, in dbapi
return __import__('MySQLdb')

next, it tells me to open cmd and type "from guestbook import db". When I hit enter, cmd says "no module called guestbook".



when I go to http://www.phpmyadmin.co I see no database I would create....




....so... I don't know, can somebody help plz? :( How do I create this database, or what module am I missing or... what us wrong, plz? :(

Thanx.

Peter the Noob Noob

wait!

app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://sql11200793:[email protected]/sql11200793'
I have no MySQL database (there is some error in system and MySQL won't install)

Could be this the problem?
Reply


Messages In This Thread
SQL Alchemy, database does not work - by Peter_EU - Oct-23-2017, 03:18 PM
RE: SQL Alchemy, database does not work - by Chuy - Oct-28-2017, 06:20 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020