I tried the following for manually mapping the tables:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from sqlalchemy import *
from sqlalchemy import dialects
from sqlalchemy import sql
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.sql.expression import *
engine = create_engine("mysql+oursql://XXXXXXXX:XXXXXXX@XXXXXXXXXXXXXX/
XXXXXXX?charset=utf8&use_unicode=True&autoping=True", echo=True)
metadata = MetaData(engine)
Base = declarative_base()
class User(Base):
__tablename__ = "users"
id = Column(Integer, primary_key=True),
login = Column(String(25)),
name = Column(String(50)),
passwd = Column(String(100)),
email = Column(String(100)),
atype = Column(String(50)),
active = Column(Boolean),
customers_id = Column('customers_id', Integer,
ForeignKey('customers.id')),
lastlogin = Column('last_login', DateTime)
customer = relationship("Customer")
def __init__(self, login, name, passwd):
self.login = login
self.name = name
self.passwd = passwd
def __repr__(self):
return "<User('%s','%s,'%s')>" % (self.login, self.name,
self.passwd)
class Customer(Base):
__tablename__ = 'customers'
id = Column(Integer, primary_key=True),
name = Column(String(100)),
doc = Column(String(25)),
email = Column(String(100)),
active = Column(Boolean)
Session = sessionmaker(bind=engine)
session = Session()
But I'm getting the following error:
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute name: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute passwd: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute atype: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute id: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute customers_id: possibly a
copy-and-paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute email: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute login: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
/Library/Frameworks/Python.framework/Versions/3.2/lib/python3.2/site-
packages/sqlalchemy/ext/declarative.py:1165: SAWarning: Ignoring
declarative-like tuple value of attribute active: possibly a copy-and-
paste error with a comma left at the end of the line?
_as_declarative(cls, classname, cls.__dict__)
Traceback (most recent call last):
File "/Users/yg/Developer/sandbox/samanual/sa.py", line 59, in
<module>
class User(Base):
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/site-packages/sqlalchemy/ext/declarative.py", line 1165, in
__init__
_as_declarative(cls, classname, cls.__dict__)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/site-packages/sqlalchemy/ext/declarative.py", line 1158, in
_as_declarative
**mapper_args)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/site-packages/sqlalchemy/orm/__init__.py", line 889, in
mapper
return Mapper(class_, local_table, *args, **params)
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/site-packages/sqlalchemy/orm/mapper.py", line 214, in
__init__
self._configure_pks()
File "/Library/Frameworks/Python.framework/Versions/3.2/lib/
python3.2/site-packages/sqlalchemy/orm/mapper.py", line 733, in
_configure_pks
(self, self.mapped_table.description))
sqlalchemy.exc.ArgumentError: Mapper Mapper|User|users could not
assemble any primary key columns for mapped table 'users'
Any ideas?
Thanks!
On Aug 17, 7:25 pm, Ygor Lemos <[email protected]> wrote:
> Seems fine to me :) I'll be happy to help on SQLSoup future.
>
> Please let me know if anyone on the list responds on behalf of this
> bug. I can help with further data if needed.
>
> Thanks Michael !
>
> On Aug 17, 7:20 pm, Michael Bayer <[email protected]> wrote:
>
>
>
>
>
>
>
> > On Aug 17, 2011, at 5:19 PM, Ygor Lemos wrote:
>
> > > I've got the same error on Python 2.7 under Mac OS X 10.7.1 running
> > > with oursql 0.9.2 for Python 2.x.
>
> > > But I really need Python 3 for this project as I have developed a web
> > > framework (soon to be published on GitHub as Serendipity) that is
> > > intrinsically linked against Python 3. This framework uses SQLAlchemy
> > > SqlSoup as the alternative for connecting to relational databases as
> > > it also have pluggable models for NoSQL DB's like MongoDB, CouchDB,
> > > etc...
>
> > > The ultimate goal is to provide automatic mapping on relational
> > > databases for rapid application development.
>
> > > Actually everything but relations is working fine.
>
> > > I have not tested yet with manual mappings.
>
> > > Are there any plans for SqlSoup continuation?
>
> > It's likely this is some simple bug in SqlSoup. I've never seen this
> > error in particular which leads me to believe the "relate()" command of
> > SqlSoup is probably not that widely used. I've asked on the development
> > list if anyone is willing to debug into simple issues like these.
>
> > The vast majority of SQLA users are on Declarative so if you'd like to
> > standardize on SqlSoup, that's great, but you might need to help out with
> > maintenance if you want your users to stay happy with it. It's a very
> > simple module.
>
> > > On Aug 17, 5:39 pm, Michael Bayer <[email protected]> wrote:
> > >> We don't have very good support for SqlSoup as it was written many years
> > >> ago and is only updated occasionally, can you reproduce your error using
> > >> normal SQLAlchemy mappings + table reflection ? Or at least trying
> > >> Python 2 ?
>
> > >> On Aug 17, 2011, at 3:53 PM, Ygor Lemos wrote:
>
> > >>> Hi,
>
> > >>> I was trying to do a simple relate according to SqlSoup documentation,
> > >>> but this error keeps popping every time for every tables I try to
> > >>> relate even though the foreign keys are right and valid and a manual
> > >>> SQL join works normally:
>
> > >>>>>> db.audits.relate('customer', db.customers)
> > >>> 2011-08-17 16:46:22,560 INFO sqlalchemy.engine.base.Engine SELECT
> > >>> DATABASE()
> > >>> 2011-08-17 16:46:22,561 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,564 INFO sqlalchemy.engine.base.Engine SHOW
> > >>> VARIABLES LIKE 'lower_case_table_names'
> > >>> 2011-08-17 16:46:22,564 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,565 INFO sqlalchemy.engine.base.Engine SHOW
> > >>> COLLATION
> > >>> 2011-08-17 16:46:22,565 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,571 INFO sqlalchemy.engine.base.Engine SHOW
> > >>> VARIABLES LIKE 'sql_mode'
> > >>> 2011-08-17 16:46:22,571 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,592 INFO sqlalchemy.engine.base.Engine SHOW CREATE
> > >>> TABLE `audits`
> > >>> 2011-08-17 16:46:22,592 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,595 INFO sqlalchemy.engine.base.Engine SHOW CREATE
> > >>> TABLE `customers`
> > >>> 2011-08-17 16:46:22,595 INFO sqlalchemy.engine.base.Engine ()
> > >>> 2011-08-17 16:46:22,597 INFO sqlalchemy.engine.base.Engine SHOW CREATE
> > >>> TABLE `users`
> > >>> 2011-08-17 16:46:22,597 INFO sqlalchemy.engine.base.Engine ()
> > >>>>>> a = db.audits.first()
> > >>> 2011-08-17 16:46:39,724 INFO sqlalchemy.engine.base.Engine BEGIN
> > >>> (implicit)
> > >>> 2011-08-17 16:46:39,725 INFO sqlalchemy.engine.base.Engine SELECT
> > >>> audits.id AS audits_id, audits.site AS audits_site, audits.zeit AS
> > >>> audits_zeit, audits.responsible AS audits_responsible, audits.prologue
> > >>> AS audits_prologue, audits.checklists AS audits_checklists,
> > >>> audits.utype AS audits_utype, audits.customers_id AS
> > >>> audits_customers_id, audits.users_id AS audits_users_id
> > >>> FROM audits
> > >>> LIMIT ?, ?
> > >>> 2011-08-17 16:46:39,725 INFO sqlalchemy.engine.base.Engine (0, 1)
>
> > >>>>>> a
> > >>> MappedAudits(id=179,site='123',zeit=datetime.datetime(2011, 8, 15, 3,
> > >>> 20,
> > >>> 38),responsible='123',prologue='123',checklists='4',utype=None,customers_id
> > >>> =1,users_id=3)
>
> > >>>>>> a.customer
> > >>> 2011-08-17 16:46:48,668 INFO sqlalchemy.engine.base.Engine SELECT
> > >>> customers.id AS customers_id, customers.name AS customers_name,
> > >>> customers.doc AS customers_doc, customers.email AS customers_email,
> > >>> customers.active AS customers_active
> > >>> FROM customers
> > >>> WHERE customers.id = ?
> > >>> 2011-08-17 16:46:48,668 INFO sqlalchemy.engine.base.Engine (1,)
>
> > >>> Traceback (most recent call last):
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/ext/sqlsoup.py", line 474, in _compare
> > >>> t2 = [getattr(o, k) for k in L]
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/ext/sqlsoup.py", line 474, in <listcomp>
> > >>> t2 = [getattr(o, k) for k in L]
> > >>> AttributeError: 'symbol' object has no attribute 'active'
>
> > >>> During handling of the above exception, another exception occurred:
>
> > >>> Traceback (most recent call last):
> > >>> File "<stdin>", line 1, in <module>
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/orm/attributes.py", line 168, in __get__
> > >>> return self.impl.get(instance_state(instance),dict_)
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/orm/attributes.py", line 424, in get
> > >>> if value in (PASSIVE_NO_RESULT, NEVER_SET):
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/ext/sqlsoup.py", line 487, in __eq__
> > >>> t1, t2 = _compare(self, o)
> > >>> File "/usr/local/lib/python3.2/dist-packages/SQLAlchemy-0.7.2-
> > >>> py3.2.egg/sqlalchemy/ext/sqlsoup.py", line 476, in _compare
> > >>> raise TypeError('unable to compare with %s' % o.__class__)
> > >>> TypeError: unable to compare with <class
> > >>> 'sqlalchemy.util.langhelpers.symbol'>
>
> > >>> My Foreign keys are all correctly setup and as a simple relation this
> > >>> should just work, but I have no idea on what is going on with this.
> > >>> Anybody had the same issue ?
>
> > >>> Follows a description of my environment and the related tables:
>
> > >>> OS: Tested on both Linux Ubuntu Natty 64bit and Mac OS X 10.7.1 Lion.
> > >>> Python: Python 3.2.1
> > >>> SQLAlchemy: 0.7.2
> > >>> MySQL: 5.5.12
> > >>> MySQL Python Driver/Connector: OurSQL 0.9.2
>
> > >>> Follows the tables description:
>
> > >>> === audits ===
>
> > >>> CREATE TABLE `audits` (
> > >>> `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
> > >>> `site` varchar(45) CHARACTER SET latin1 DEFAULT NULL,
> > >>> `zeit` datetime NOT NULL COMMENT 'date the audit was started (zeit =
> > >>> german for time)',
> > >>> `responsible` varchar(100) CHARACTER SET latin1 NOT NULL,
> > >>> `prologue` text CHARACTER SET latin1 COMMENT 'digest at the
> > >>> beginning',
> > >>> `checklists` varchar(30) DEFAULT ' ',
> > >>> `utype` varchar(45) DEFAULT NULL,
> > >>> `customers_id` int(10) unsigned NOT NULL,
> > >>> `users_id` int(10) unsigned NOT NULL,
> > >>> PRIMARY KEY (`id`),
> > >>> KEY `fk_audits_users1` (`users_id`),
> > >>> KEY `utype` (`utype`) USING BTREE,
> > >>> KEY `fk_audits_customers1` (`customers_id`),
> > >>> CONSTRAINT `fk_audits_customers1` FOREIGN KEY (`customers_id`)
> > >>> REFERENCES `customers` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
> > >>> CONSTRAINT `fk_audits_users1` FOREIGN KEY (`users_id`) REFERENCES
> > >>> `users` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
> > >>> ) ENGINE=InnoDB AUTO_INCREMENT=235 DEFAULT CHARSET=utf8
>
> > >>> === customers ===
>
> > >>> customers | CREATE TABLE `customers` (
> > >>> `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
> > >>> `name` varchar(100) CHARACTER SET latin1 NOT NULL,
> > >>> `doc` varchar(25) CHARACTER SET latin1 NOT NULL,
> > >>> `email` varchar(100) CHARACTER SET latin1 DEFAULT NULL,
> > >>> `active` tinyint(1) DEFAULT '1',
> > >>> PRIMARY KEY (`id`),
> > >>> UNIQUE KEY `customers_index_name` (`name`),
> > >>> UNIQUE KEY `customers_index_doc` (`doc`)
> > >>> ) ENGINE=InnoDB AUTO_INCREMENT=20 DEFAULT CHARSET=utf8
>
> > >>> Thanks!
>
> > >>> --
> > >>> You received this message because you are subscribed to the Google
> > >>> Groups "sqlalchemy" group.
> > >>> To post to this group, send email to [email protected].
> > >>> To unsubscribe from this group, send email to
> > >>> [email protected].
> > >>> For more options, visit this group
> > >>> athttp://groups.google.com/group/sqlalchemy?hl=en.
>
> > > --
> > > You received this message because you are subscribed to the Google Groups
> > > "sqlalchemy" group.
> > > To post to this group, send email to [email protected].
> > > To unsubscribe from this group, send email to
> > > [email protected].
> > > For more options, visit this group
> > > athttp://groups.google.com/group/sqlalchemy?hl=en.
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.