Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2213 (closed documentation: migrated)

Opened 10 years ago

Last modified 8 years ago

Reflection tables on model for tg2.

Reported by: beyonlo Owned by: jorge.vargas
Priority: normal Milestone: 2.1 docs
Component: TurboGears Version: 2.0
Severity: normal Keywords:
Cc:

Description (last modified by jorge.vargas) (diff)

Hello,

In tg1 I use mapper in model.py to do a reflect tables from database to SqlAlchemy? (SA). With this relflect don't needs create all columns in model again, because talbles already created in database. But in TG2 I try the same, like as working in tg1, but not works for me.

In tg1 I was do for example in model.py:

cadcar_table = Table('cadcar',metadata, autoload=True, schema="car")
class Cadcar(object):
    pass
mapper(Cadcar, cadcar_table)

But this (reflect) not works in tg2. I Would like know how I do this in tg2, like as in tg1.

Thank you!

Change History

comment:1 Changed 10 years ago by beyonlo

  • Type changed from defect to task

comment:2 Changed 10 years ago by mramm

There are some hints in model.py for how to do this, but basically you need to do the refelection inside init_model so that it can be deferred to later in the application load process when the SQLAlchemy metadata is setup for you.

If you are still having trouble, could you post a traceback and link to it here so we can try to help you better?

Thank!

comment:3 Changed 10 years ago by jorge.vargas

  • Owner changed from faide to Chris Arndt
  • Component changed from TurboGears to Documentation
  • Description modified (diff)

This seems like something we need to clarify rather than fix.

comment:4 Changed 10 years ago by mramm

  • Status changed from new to closed
  • Resolution set to fixed

There's even an example of how to do this in quickstart now.

comment:5 Changed 10 years ago by jorge.vargas

  • Status changed from closed to reopened
  • Resolution fixed deleted

I'm reopening because I just stumbled upon this error.

I'm using the following as example code.

#1    metadata.reflect(bind=engine)
    from sqlalchemy import Table
    global Site
    class Site(DeclarativeBase):
#1        __table__ = metadata.tables['site']
#2        __table__ = Table('site',metadata,autoload=True)
#3        __table__ = Table('site',metadata,autoload=True,autoload_with=engine)


1- the first table declaration works (and the reflect all at line1) 2- This line does not works (this is the example in quickstart) 3- This line does work

Reflection made with a mysql database.

comment:6 Changed 10 years ago by jorge.vargas

  • Owner changed from Chris Arndt to jorge.vargas
  • Status changed from reopened to new

comment:7 Changed 10 years ago by jorge.vargas

  • Milestone changed from 2.0rc1 to 2.1a1

comment:8 Changed 10 years ago by jorge.vargas

  • Component changed from Documentation to TurboGears
  • Type changed from task to documentation

comment:9 Changed 10 years ago by percious

  • Milestone changed from 2.1a1 to 2.1 docs

comment:10 Changed 8 years ago by chrisz

  • Version set to 2.0

comment:11 Changed 8 years ago by pedersen

  • Status changed from new to closed
  • Resolution set to migrated
Note: See TracTickets for help on using tickets.