> if u look up the stacktrace/traceback, u'll see which statement in
> your own code triggered the error. is it in the mapping-part or is
> still in table-declaration part?
> do all 3 tables use same metadata?
Thank you for your comments so far, I appreciate you helping me out on this.
The entire stack trace is below:
Traceback (most recent call last):
File "test.py", line 9, in <module>
my_device = post.post("3F8ADE52-4F63-11DD-9AF0-90BB55D89593", "Title",
"Content")
File "/var/lib/python-support/python2.5/sqlalchemy/orm/attributes.py",
line 1211, in init
extra_init(class_, oldinit, instance, args, kwargs)
File "/var/lib/python-support/python2.5/sqlalchemy/orm/mapper.py", line
798, in extra_init
self.compile()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/mapper.py", line
350, in compile
mapper.__initialize_properties()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/mapper.py", line
371, in __initialize_properties
prop.init(key, self)
File "/var/lib/python-support/python2.5/sqlalchemy/orm/interfaces.py",
line 374, in init
self.do_init()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/properties.py",
line 467, in do_init
self.__determine_joins()
File "/var/lib/python-support/python2.5/sqlalchemy/orm/properties.py",
line 521, in __determine_joins
self.secondaryjoin = _search_for_join(self.mapper,
self.secondary).onclause
File "/var/lib/python-support/python2.5/sqlalchemy/orm/properties.py",
line 514, in _search_for_join
return sql.join(mapper.local_table, table)
File "/var/lib/python-support/python2.5/sqlalchemy/sql/expression.py",
line 116, in join
return Join(left, right, onclause, isouter)
File "/var/lib/python-support/python2.5/sqlalchemy/sql/expression.py",
line 2275, in __init__
self.onclause = self.__match_primaries(self.left, self.right)
File "/var/lib/python-support/python2.5/sqlalchemy/sql/expression.py",
line 2317, in __match_primaries
return sql_util.join_condition(primary, secondary)
File "/var/lib/python-support/python2.5/sqlalchemy/sql/util.py", line 74,
in join_condition
col = fk.get_referent(a)
File "/var/lib/python-support/python2.5/sqlalchemy/schema.py", line 755,
in get_referent
return table.corresponding_column(self.column)
File "/var/lib/python-support/python2.5/sqlalchemy/schema.py", line 788,
in column
"foreign key" % tname)
sqlalchemy.exceptions.NoReferencedTableError: Could not find table 'post'
with which to generate a foreign key
I've also attached the two modules and the test script I'm trying to use, if
you wouldn't mind taking a look an letting me know what I'm doing wrong, I
would really appreciate it.
Cheers,
Heston
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---
# Class Imports
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
# Configure the delarative base for SQL Alchemy.
Base = declarative_base()
# Define the Remote Device class.
class keyword(Base):
# Define the table for SQL Aclchemy
__tablename__ = "keyword"
# Define the class properties for SQL Alchemy
keyword_id = Column(Integer, primary_key=True)
word = Column(String)
# I'm the class constructor method.
def __init__(self, keyword_id="", word=""):
self.keyword_id = keyword
self.word = word
# Class Imports
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Table, Column, Integer, String, MetaData, ForeignKey
from sqlalchemy.orm import relation, backref
import keyword
# Configure the delarative base for SQL Alchemy.
Base = declarative_base()
metadata = MetaData()
post_keyword = Table("post_keyword", metadata,
Column("post_id", String, ForeignKey('post.post_id')),
Column('keyword_id', Integer,
ForeignKey('keyword.keyword_id'))
)
# Define the Remote Device class.
class post(Base):
# Define the table for SQL Aclchemy
__tablename__ = "post"
# Define the class properties for SQL Alchemy
post_id = Column(String, primary_key=True)
title = Column(String)
content = Column(String)
# many to many BlogPost<->Keyword
keywords = relation(keyword.keyword, secondary=post_keyword, backref="post")
# I'm the class constructor method.
def __init__(self, post_id="", title="", content=""):
self.post_id = post_id
self.title = title
self.content = content
import post
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
engine = create_engine("connectionstring", echo=False)
Session = sessionmaker(bind=engine)
my_session = Session()
my_device = post.post("3F8ADE52-4F63-11DD-9AF0-90BB55D89593", "Title",
"Content")
my_session.save_or_update(my_device)
my_session.commit()