Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sqlalchemy.exc.InvalidRequestError: Class does not have a mapped column named #74

Open
hello-josh opened this issue Apr 22, 2014 · 3 comments

Comments

@hello-josh
Copy link

I am getting the following error on startup while trying to launch via sandmanctl mysql://root@localhost/instanthunt

sqlalchemy.exc.InvalidRequestError: Class <class 'flask_sqlalchemy.user_submission_vote'> does not have a mapped column named 'submitter_idclue_id'

I think it is having trouble handling a composite foreign key? Or is it because the field names do not match on both tables? This table's submitter_id maps to the foreign table's user_id

CREATE TABLE `user_submission_vote` (
  `user_id` int(11) NOT NULL,
  `submitter_id` int(11) NOT NULL COMMENT 'fk to user_submission.user_id',
  `clue_id` int(11) NOT NULL,
  `vote` tinyint(1) NOT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`user_id`,`submitter_id`,`clue_id`),
  KEY `fk_user_vote_user_submission_id` (`submitter_id`,`clue_id`),
  CONSTRAINT `fk_user_vote_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_user_vote_user_submission_id` FOREIGN KEY (`submitter_id`, `clue_id`) REFERENCES `user_submission` (`user_id`, `clue_id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Here is the other table for completeness

CREATE TABLE `user_submission` (
  `user_id` int(11) NOT NULL,
  `clue_id` int(11) NOT NULL,
  `storage_uri` varchar(255) NOT NULL COMMENT 'Public URI to find the jpeg image in storage',
  `lat` decimal(10,6) DEFAULT NULL,
  `lng` decimal(10,6) DEFAULT NULL,
  `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated` timestamp NULL DEFAULT NULL,
  PRIMARY KEY (`user_id`,`clue_id`),
  KEY `fk_user_submission_clue_id` (`clue_id`),
  CONSTRAINT `fk_user_submission_clue_id` FOREIGN KEY (`clue_id`) REFERENCES `clue` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
  CONSTRAINT `fk_user_submission_user_id` FOREIGN KEY (`user_id`) REFERENCES `user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8

I have a Spring+Hibernate app using these relations right now so I'm pretty sure the table definitions aren't an issue.

@jeffknupp
Copy link
Owner

Could you past the full error traceback? Not sure where it's even getting the name submitter_idclue_id from...

@hello-josh
Copy link
Author

Had a busy day yesterday. Here is it

Traceback (most recent call last):
  File "/Users/Josh/Developer/Github/josh/bin/sandmanctl", line 9, in <module>
    load_entry_point('sandman==0.9.4', 'console_scripts', 'sandmanctl')()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/sandman-0.9.4-py2.7.egg/sandman/sandmanctl.py", line 73, in main
    activate(name='sandmanctl')
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/sandman-0.9.4-py2.7.egg/sandman/model/utils.py", line 166, in activate
    register_classes_for_admin(db.session, show_pks, name)
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/sandman-0.9.4-py2.7.egg/sandman/model/utils.py", line 140, in register_classes_for_admin
    admin_view.add_view(admin_view_class(cls, db_session))
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/contrib/sqla/view.py", line 271, in __init__
    super(ModelView, self).__init__(model, name, category, endpoint, url)
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/model/base.py", line 515, in __init__
    self._refresh_cache()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/model/base.py", line 523, in _refresh_cache
    self._list_columns = self.get_list_columns()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/model/base.py", line 644, in get_list_columns
    columns = self.scaffold_list_columns()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/contrib/sqla/view.py", line 322, in scaffold_list_columns
    for p in self._get_model_iterator():
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/Flask_Admin-1.0.8-py2.7.egg/flask_admin/contrib/sqla/view.py", line 293, in _get_model_iterator
    return model._sa_class_manager.mapper.iterate_properties
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/mapper.py", line 1782, in iterate_properties
    configure_mappers()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/mapper.py", line 2560, in configure_mappers
    mapper._post_configure_properties()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/mapper.py", line 1673, in _post_configure_properties
    prop.init()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/interfaces.py", line 143, in init
    self.do_init()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/relationships.py", line 1509, in do_init
    self._process_dependent_arguments()
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/orm/relationships.py", line 1534, in _process_dependent_arguments
    setattr(self, attr, attr_value())
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/ext/declarative/clsregistry.py", line 263, in __call__
    x = eval(self.arg, globals(), self._dict)
  File "<string>", line 1, in <module>
  File "/Users/Josh/Developer/Github/josh/lib/python2.7/site-packages/SQLAlchemy-0.9.4-py2.7-macosx-10.8-x86_64.egg/sqlalchemy/ext/declarative/clsregistry.py", line 197, in __getattr__
    % (self.cls, key))
sqlalchemy.exc.InvalidRequestError: Class <class 'flask_sqlalchemy.user_submission_flagged'> does not have a mapped column named 'submitter_idclue_id'

@aczapszys
Copy link

This issue would be fixed by #95

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants