AttributeError: type object 'SQLAlchemy' has no attribute 'Model'

python

#1

Hi All,

Running this command returns an unexplainable error:

(venv) :~/workspace/flask_blog $ python manage.py shell
Traceback (most recent call last):
File “manage.py”, line 8, in
from flask_blog import app
File “/home/ubuntu/workspace/flask_blog/init.py”, line 12, in
from blog import views
File “/home/ubuntu/workspace/flask_blog/blog/views.py”, line 5, in
from author.models import Author
File “/home/ubuntu/workspace/flask_blog/author/models.py”, line 3, in
class Author(db.Model):
AttributeError: type object ‘SQLAlchemy’ has no attribute ‘Model’

Maybe the lack of knowledge of c9, I really see no connection between the shell command running and the SQLAlchemy Model, any help is greatly appreciated.
Thank you very much,
Roman


#2

I don’t understand the error but I wouldn’t say it’s unexplainable :smile: Some things to look at would be:

  1. Make sure all packages you’re importing are installed.
  2. Look at how you’re using SQLAlchemy.
  3. Not sure why you’re passing shell into the command but make sure that’s right.
  4. Look for other errors in your code.

If those things don’t bear fruit and no Python experts offer help here then you may try posting on Stack Overflow about this. Also would be good to see the contents of the file you’re running.


#3

Hi Brady,

Thanks for the answer, it gave me hints where to look for the error - 2nd point was the winning one. It was a missing “app” argument in db = SQLAlchemy(app) line.

Regards,
Roman