Forums

flask mysql AttributeError: 'NoneType' object has no attribute 'drivername'

Hi,

I tried to run the db_create.py to create the tables but encountered an error.

03:38 ~/mysite (master)$ python db_create.py
Traceback (most recent call last):
File "db_create.py", line 4, in <module>
db.create_all()
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy.py", line 822, in create_all
self._execute_for_all_tables(app, bind, 'create_all')
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy.py", line 814, in _execute_for_all_tables
op(bind=self.get_engine(app, bind), tables=tables)
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy.py", line 763, in get_engine
return connector.get_engine()
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy.py", line 438, in get_engine
self._sa.apply_driver_hacks(self._app, info, options)
File "/usr/local/lib/python2.7/dist-packages/flask_sqlalchemy.py", line 706, in apply_driver_hacks
if info.drivername == 'mysql':
AttributeError: 'NoneType' object has no attribute 'drivername'

My mysqlconnection:

os.environ['DATABASE_URL'] = "mysql+mysqldb://coinage:mypassword:@coinage.mysql.pythonanywhere- services.com/coinage$sampledb, pool_recycle=280"

Any inputs are much appreciated.

Thanks.

Is DATABASE_URL set in the console that you're using?

echo $DATABASE_URL

The os.environ looks like it's probably being set in the WSGI file and that doesn't get set in consoles. You need to set it yourself if you want to run things in the console that have access to it.

DATABASE_URL = 'mysql+mysqldb://coinage:mypassword:@coinage.mysql.pythonanywhere- services.com/coinage$sampledb'

Note the single quotes in the command above. They are important.

Also, I don't think that pool_recycle is part of the DATABASE_URL. It's part of the call to create_engine . Use:

os.environ['DATABASE_URL'] = "mysql+mysqldb://coinage:mypassword:@coinage.mysql.pythonanywhere- services.com/coinage$sampledb"

Thanks glenn. I added the setting of DATABASE_URL in my db_create.py and it solves the problem

Great! Thanks for confirming.