On Thu, Jun 19, 2008 at 8:44 PM, Jonathan LaCour
<[EMAIL PROTECTED]> wrote:
>
> lilo wrote:
>
>>
>> I have tried this command:
>> a.a_metadata.drop_all(bind=db)
>> a.a_metadata.create_all(bind=db)
>>
>> and they don't create any tables and I don't get any error at all.
>>
>> With, setup_all(True, bind=db), creates table A and B on each
>> engine. I just want table A on m1,m2 and table B on n1,n2. I
>> have spent quite some time searching and going over the docs but I
>> can't figure out the problem is.
>
> You aren't actually telling the entities which metadata they belong
> to. The documentation clearly instructs you how to do this on this
> page:
>
> http://elixir.ematia.de/apidocs/elixir.options.html
>
> The relevant section discusses the `using_options` statement, states
> that you can pass a `metadata` keyword argument:
>
> Specify a custom MetaData for this entity. By default, entities
> uses the global elixir.metadata. This option can also be set for
> all entities of a module by setting the __metadata__ attribute
> of that module.
Well, he does try to use the __metadata__ attribute. There are several
problems in the code though: in the version with the commented
setup_all(True) is that there is not setup_all() call at all, which
means the table objects are not created in their respective metadata,
so issuing metadata.create_all() does nothing indeed.
The other problems are:
* using __metada__ instead of __metadata__ !!!
* reusing the same metadata for both modules (even if inside another
variable), produce the unwanted result of creating A and B on each
engine.
Attached are the corrected files.
Hope it helps,
--
Gaƫtan de Menten
http://openhex.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"SQLElixir" 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/sqlelixir?hl=en
-~----------~----~----~----~------~----~------~--~---
### file a.py
from elixir import *
from sqlalchemy import MetaData
a_metadata = MetaData()
__metadata__ = a_metadata
class A(Entity):
using_options(tablename='a')
aname = Field(String(30), primary_key=True)
### file b.py
from elixir import *
from sqlalchemy import MetaData
b_metadata = MetaData()
__metadata__ = b_metadata
class B(Entity):
using_options(tablename='b')
bname = Field(String(30), primary_key=True)
### file c.py
#!/usr/bin/env python
from sqlalchemy import create_engine
from elixir import *
import b
import a
m1 = create_engine("sqlite:///", echo=True)
m2 = create_engine("sqlite:///", echo=True)
n1 = create_engine("sqlite:///", echo=True)
n2 = create_engine("sqlite:///", echo=True)
setup_all()
# create tables
for db in (m1, m2):
a.a_metadata.drop_all(bind=db)
a.a_metadata.create_all(bind=db)
for db in (n1, n2):
b.b_metadata.drop_all(bind=db)
b.b_metadata.create_all(bind=db)