Forums

Tables not created

Flask application using flask_sqlalchemy and MySQL database. After importing db and creating tables ( db.create_all() ) in ipython3.7 I don't get any errors. But when I go check if the tables are created (show tables;) I get Empty set. The application is still running, no error or what so ever. I did confirm username, password, databasename..etc what could I be doing wrong?

Are you using a MySQL console when you run "show tables;"? Or starting mysql from inside a bash session?

Using MySQL console... accessed on the database page via the database name link.

Can I take a look at your code? We can see it from our admin interface, but we always ask for permission first.

yes you can

... "mysql+mysqlconnector://{username}:{password}@{hostname}/{databasename}" now when i run db.create_all() i get this error

ModuleNotFoundError: No module named 'mysql'

giles...

were you using a virtualenv at any point? do you have mysql installed into it? when you ran the above command was it inside of a virtualenv with mysql installed?

yes to all of the above questions

from within your virtualenv- if you start a python console, and try to import mysql, what do you get?

the import works... no error(s)

then your flask application is not using your virtualenv

so you suggest i don't use the venv?

No, @conrad is saying that you have not configured your web app to use your virtualenv. If you want to use a virtualenv, you need to tell your web app which one to use.

I have configured the app to use virtualenv, I have created multiple databases yet when I run the db.create_all() command I get no errors but no tables are created. I consent that you look at my code. Pheeg/uvenv

got it.

Did you work out what the problem was?

Yes, I had to import the tables before the db.create_all() command.

another thing, half of the python files(.py) have duplicated in .pyc extensions, any idea what this is? can delete them? __init__.pyc

Here you go: http://net-informations.com/python/iq/pyc.htm

Very informative site... thank you.