Hi,
i need some help/advice in defining my classes with the declarative
syntax from sqlalchemy.
This is the current situation:
I have one table in my Database which is a Oracle "Database Link". The
name of this "Database Link" is a...@adr. I created a view for this
"Database Link" called unternehmen.
Thats my syntax for the view unternehmen:
class Unternehmen(Base):
""" this table is an already existend view in a oracle db"""
__tablename__ = 'unternehmen'
mnr = Column(String(12), primary_key=True)
name1 = Column("NAME1", String(33))
This works so far... great :)
Ok now a second table comes into the game. The name of this table is
BTeilnehmer. As you can see this table has a ForeignKey to
Unternehmen.mnr. I use a seperate metadata BaseC for it because i want
to create this table.
BaseC = declarative_base()
class BTeilnehmer(BaseC):
__tablename__ = 'bteilnehmer'
b_id = Column(Integer(12), Sequence('dd_seq'), primary_key=True)
name = Column(String(12))
company_mnr = Column(String(12), ForeignKey(Unternehmen.mnr))
company = relation(Unternehmen,
backref = backref('unternehmen'))
If i now try to create the table BTeilnehmer with:
BaseC.metadata.create_all(engine)
it gives me this traceback:
So any ideas or suggestions.
Thanks for your help
Christian
yeti:fernlehrgang cklinger$ bin/python create.py
2010-02-24 10:05:59,090 INFO sqlalchemy.engine.base.Engine.0x...3c10
SELECT USER FROM DUAL
2010-02-24 10:05:59,091 INFO sqlalchemy.engine.base.Engine.0x...3c10 {}
2010-02-24 10:05:59,099 INFO sqlalchemy.engine.base.Engine.0x...3c10
select table_name from all_tables where table_name=:name and
owner=:schema_name
2010-02-24 10:05:59,100 INFO sqlalchemy.engine.base.Engine.0x...3c10
{'name': 'BTEILNEHMER', 'schema_name': 'FLG'}
2010-02-24 10:05:59,185 INFO sqlalchemy.engine.base.Engine.0x...3c10
select table_name from all_tables where table_name=:name and
owner=:schema_name
2010-02-24 10:05:59,185 INFO sqlalchemy.engine.base.Engine.0x...3c10
{'name': 'BTEILNEHMER', 'schema_name': 'FLG'}
2010-02-24 10:05:59,191 INFO sqlalchemy.engine.base.Engine.0x...3c10
select sequence_name from all_sequences where sequence_name=:name and
sequence_owner=:schema_name
2010-02-24 10:05:59,191 INFO sqlalchemy.engine.base.Engine.0x...3c10
{'name': 'DD_SEQ', 'schema_name': 'FLG'}
2010-02-24 10:05:59,214 INFO sqlalchemy.engine.base.Engine.0x...3c10
CREATE TABLE bteilnehmer (
b_id INTEGER NOT NULL,
name VARCHAR(12),
company_mnr VARCHAR(12),
PRIMARY KEY (b_id),
FOREIGN KEY(company_mnr) REFERENCES unternehmen (mnr)
)
2010-02-24 10:05:59,215 INFO sqlalchemy.engine.base.Engine.0x...3c10 {}
2010-02-24 10:05:59,228 INFO sqlalchemy.engine.base.Engine.0x...3c10
ROLLBACK
Traceback (most recent call last):
File "create.py", line 37, in <module>
BaseC.metadata.create_all(engine)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/schema.py",
line 1811, in create_all
bind.create(self, checkfirst=checkfirst, tables=tables)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 1129, in create
self._run_visitor(self.dialect.schemagenerator, entity,
connection=connection, **kwargs)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 1158, in _run_visitor
visitorcallable(self.dialect, conn, **kwargs).traverse(element)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/visitors.py",
line 89, in traverse
return traverse(obj, self.__traverse_options__, self._visitor_dict)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/visitors.py",
line 200, in traverse
return traverse_using(iterate(obj, opts), obj, visitors)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/visitors.py",
line 194, in traverse_using
meth(target)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/compiler.py",
line 831, in visit_metadata
self.traverse_single(table)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/visitors.py",
line 79, in traverse_single
return meth(obj)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/sql/compiler.py",
line 870, in visit_table
self.execute()
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 1812, in execute
return self.connection.execute(self.buffer.getvalue())
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 824, in execute
return Connection.executors[c](self, object, multiparams, params)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 888, in _execute_text
return self.__execute_context(context)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 896, in __execute_context
self._cursor_execute(context.cursor, context.statement,
context.parameters[0], context=context)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 950, in _cursor_execute
self._handle_dbapi_exception(e, statement, parameters, cursor, context)
File
"/Users/cklinger/work/fernlehrgang/lib/python2.6/site-packages/SQLAlchemy-0.5.8-py2.6.egg/sqlalchemy/engine/base.py",
line 931, in _handle_dbapi_exception
raise exc.DBAPIError.instance(statement, parameters, e,
connection_invalidated=is_disconnect)
sqlalchemy.exc.DatabaseError: (DatabaseError) ORA-02270: no matching
unique or primary key for this column-list
'\nCREATE TABLE bteilnehmer (\n\tb_id INTEGER NOT NULL, \n\tname
VARCHAR(12), \n\tcompany_mnr VARCHAR(12), \n\tPRIMARY KEY (b_id), \n\t
FOREIGN KEY(company_mnr) REFERENCES unternehmen (mnr)\n)\n\n' {}
yeti:fernlehrgang cklinger$
--
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en.