There is a recipe for dropping FK constraints:
http://www.sqlalchemy.org/trac/wiki/UsageRecipes
did you find that?
In addition, if you wanted to keep the FKs enabled, there is an example
here using Metadata.sorted_tables, to get the table list in dependency
order.
Here is code that works for me:
from datetime import datetime
from sqlalchemy import Column, DateTime, Integer, create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite://', echo=True)
Base =
You can reflect once, then cache the metadata (e.g. pickle it)
then I think you can use autoload with usexisting
On Apr 30, 12:13 am, Kuze kuze.to...@gmail.com wrote:
I'm aware SQLAlchemy provides a comprehensive package for creating
database objects (tables, indexes, etc.) with a simple
Try virtualenv
http://pypi.python.org/pypi/virtualenv
On Apr 26, 2:31 pm, Mathieu Tozer math...@madebysofa.com wrote:
Is it possible to have multiple installation versions on the one machine? I
don't want to screw with my dev environment too much but want to try
migrating up.
--
You
Looks like you need to specify a composite ForeignKey
http://www.sqlalchemy.org/docs/core/schema.html?highlight=foreign_keys#sqlalchemy.schema.ForeignKeyConstraint
comment_table = Table('comment',metadata,
Column('id',Integer,primary_key=True),
Column('package_id', Integer),
Hi,
Do you need to store expiry_code? seeing as it is a function of
last_con and the current date.
class PhNumber(Base):
__tablename__ = 'ph_numbers'
ph_no = Column(Integer, nullable=False)
last_con = Column(DateTime, nullable=False)
@property
def expiry_code(self):
msg = 'Expired
GHZ, it did work! Wondering about one thing though; the recipe in
the documentation iterates over the tables in reverse sorted order, like so:
for table in reversed(meta.sorted_tables)
Do you know what this would be good for (since your code does not care about
the table order)?
Arve
maybe it needs to be in a transaction:
con = engine.connect()
trans = con.begin()
for name, table in meta.tables.items():
print table.delete()
con.execute(table.delete())
trans.commit()
On Feb 14, 1:29 pm, Arve Knudsen arve.knud...@gmail.com wrote:
Hi
What's the right way to
Hi,
If I create a table with a default.
create table T (id number primary key, data number default NULL)
Then reflect this table.
then using the ORM I trigger an insert, but only into the id column
and flush()
then I try to access the 'data' attribute
this causes a select, to get the actual
AS t_data
FROM t
WHERE t.id = :param_1
2010-06-21 11:41:46,215 INFO sqlalchemy.engine.base.Engine.0x...84ec
{'param_1': 1}
On 21 Jun, 11:40, GHZ geraint.willi...@gmail.com wrote:
Hi,
If I create a table with a default.
create table T (id number primary key, data number default NULL
you should access column names via lower case
i.e.
columns = 'projectid', 'program', 'progmanger']
On 10 Jun, 03:39, Aref arefnamm...@gmail.com wrote:
Hello All,
I just began learning sqlalchemy and am not quite used to it yet so
please excuse my ignorance and which might be a trivial
you can check for primary key constraints using:
select table_name, constraint_name from user_constraints where
constraint_type = 'P'
the orm will need to know the primary keys, but if they do not exist
in the schema, you can set them when you reflect the table
t = Table('t1',
meta,
suggest seeing what happens if you take an existing table and just say
table.c.id.default = Sequence(some_sequence), which should do the job but
im not 100% sure.
On May 12, 2010, at 5:47 AM, GHZ wrote:
Hi,
Can I make the second form (metadata.reflect, then Table with
useexising=True
Hi,
Can I make the second form (metadata.reflect, then Table with
useexising=True), result in the same insert statement as the first
form (Table with autoload=True)?
Thanks.
from sqlalchemy import create_engine, Table, Column, Sequence,
MetaData, Integer
engine =
Hi,
Using plain Declarative, I am able to redefine a primary key column
that has been autoloaded, so that I can link it to an oracle sequence
and give it a new name:
Id = Column('id', Integer, Sequence('table_sq'), primary_key=True)
However, if I then try to add some methods to the class using
Hi,
http://www.sqlalchemy.org/changelog/CHANGES_0_6beta3
* 'proxy' argument on synonym() is removed. This flag
did nothing throughout 0.5, as the proxy generation
behavior is now automatic.
On 14 apr, 13:16, jose soares jose.soa...@sferacarta.com wrote:
Hi all,
seems
using 5.5
from sqlalchemy import create_engine, Table, Column,
ForeignKeyConstraint, MetaData, and_, String, Integer, ForeignKey
from sqlalchemy.orm import relation, sessionmaker, synonym, join
from sqlalchemy.ext.declarative import declarative_base
engine = create_engine('sqlite:///:memory:')
I'm reflecting an existing schema with autoload=True
All strings are stored as fixed length, which I need to strip()
Is there a way of converting all attributes of an existing type?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the
try :
m = mapper(MyJoin, a_table.join(b_table), properties={
'a_id' : [Table_a.__table__.c.id, Table_b.__table__.c.a_id]
})
from:
http://www.sqlalchemy.org/docs/05/mappers.html#mapping-a-class-against-multiple-tables
On May 5, 11:46 am, Alessandro Dentella san...@e-den.it wrote:
Hi,
I tried to use the example from:
http://www.sqlalchemy.org/docs/05/reference/ext/associationproxy.html#simplifying-association-object-relations
But with declarative syntax. Any idea why this is going wrong?
from sqlalchemy import Table, Column, Integer, String, MetaData,
ForeignKey, Sequence,
I am trying to use the association_proxy for attributes that link to
tables containing mostly static data
e.g. my static data is:
COUNTRY
COUNTRY.CODE
COUNTRY.NAME
and the data I am changing is:
USER
USER.COUNTRY_CODE
I use the association_proxy as I want to be able to say:
user = User()
Don't know if this will work in your case.. but to handle joins to so
many static tables.
Note.. I didn't need to update these tables, nor query from them back
to the data tables. (i.e. no need to call Gender.member_profiles())
I did something like the following:
class MemberProfile(Base):
to a join and just
modify your Subscriber class to break up the addresses collection
amongst a proxy of the MAIN element and a list of the remaining
elements. an attribute_mapped_collection could help to accomplish
this nicely.
On Jan 28, 2009, at 7:22 PM, GHZ wrote:
I have
I have a subscriber and address table.
a subscriber will have one and only one 'MAIN' address.
I want the subscriber and MAIN address to be represented by one class
'Subscriber'. However, I want that class to have a collection
'addresses' which contains other addresses (e.g. old addresses) -
Hi,
I have a Subscriber and an Address table. Subscriber can have many
Addresses
mapper(Subscriber, subscriber_table, properties={
'addresses' : relation(Address, collection_class=Addresses,
backref='customer')})
From the a Subscriber object, I want to inspect all loaded objects in
any
Hi,
I am using SQLA for reading from a database.
I modify the objects to use in my code, but don't want to write
anything back to the database.
therefore I call: session.expunge_all() , before reading the next set
of data.
This works, but it results in the select statements being re-parsed by
On Sep 18, 2:59 pm, Michael Bayer [EMAIL PROTECTED] wrote:
Well, I would think __table_args__ is the only argument you'd really
want to propigate in that way, and this is an inconvenience I've also
had so perhaps we'll do something about it...I would propose a
default_table_args keyword
On Sep 18, 2:54 pm, Michael Bayer [EMAIL PROTECTED] wrote:
2. more involved: catch change events and populate a Child.grandparent
relation(). 0.5 has made the AttributeExtension API public which
would be a good place to catch this event. The advantage to this is
that your Child has a
Hi,
Is there a reason why this is not used to return the id column value?
Would cut down on the number of roundtrips for insert statements
e.g.
insert into bob (id) values (bob_sq.nextval) returning id into :id
rather than what seems to be happening at the moment:
select bob_sq.nextval from
I want to set table, mapper arguments automatically.
The following is the only way I have found to do this.
Is this supported?
Am I wasting my time with Declarative and should rather use the non
declarative if I want this control?
class MyMeta(DeclarativeMeta):
def __new__(meta, classname,
Thank you Michael,
I found the changeset adding this to Postgresql. Will look into a
similar change for Oracle.
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups
sqlalchemy group.
To post to this group, send email to
I am thinking about moving from home grown data access classes, to
sqlalchemy for a simple ETL tool for moving from legacy databases - at
least for the Extract and simplest of Transformations.
Example of what I'm trying to achieve.. if I have a customer table in
the legacy database, and a
Figured it out. slight issue with documentation confused me
http://www.sqlalchemy.org/docs/05/plugins.html#plugins_declarative
'instruments' should read 'descriptor'?
--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google
now I have a real question based on example 1 above.
i.e. wanting an object with the following attributes:
customer.o_cutype
customer.id
customer.type (converted from cutype through mapping function)
from
create table old_customer (cunr number, cutype char(1));
The following works:
PREFIX
34 matches
Mail list logo