Seems SA checks if table already exist in all_tables system table...
and creates it only if it doesn't exist.

In my case...

SQL> select table_name from all_tables where 
table_name='FUNZIONE_CALCOLO', returns:
TABLE_NAME
------------------------------
FUNZIONE_CALCOLO

SQL> select table_name from all_tables where table_name='TARIFFA';
no rows selected

instead :

SQL> desc FUNZIONE_CALCOLO
ERROR:
ORA-04043: object FUNZIONE_CALCOLO does not exist

SQL> desc TARIFFA
ERROR:
ORA-04043: object TARIFFA does not exist
-------------------------------------------
probably it is because I droped the table funzione_calcolo.
Is it regular that FUNZIONE_CALCOLO is in all_tables yet?


-----------------
2.4.4 (#2, Apr 15 2008, 23:43:20)
[GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)]

select table_name from all_tables where table_name=:name

{'name': 'FUNZIONE_CALCOLO'}

select table_name from all_tables where table_name=:name

{'name': 'TARIFFA'}

CREATE TABLE tariffa (
        id INTEGER NOT NULL,
        cod_funzione_calcolo VARCHAR(5) NOT NULL,
        PRIMARY KEY (id),
         FOREIGN KEY(cod_funzione_calcolo) REFERENCES funzione_calcolo 
(codice)
)



None

ROLLBACK
Traceback (most recent call last):
  File "./start-sicer.py", line 16, in ?
    from sicer.controllers import Root
  File "/home/sfera/release/sicer/controllers/__init__.py", line 3, in ?
    from errorhandling       import ErrorCatcher
  File "/home/sfera/release/sicer/controllers/errorhandling.py", line 
16, in ?
    from sicer.model import Anagrafica
  File "/home/sfera/release/sicer/model/__init__.py", line 1, in ?
    from sql             import *
  File "/home/sfera/release/sicer/model/sql.py", line 21, in ?
    database.metadata.create_all(engine)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
1239, in create_all
    bind.create(self, checkfirst=checkfirst, tables=tables)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 699, in create
    self._run_visitor(self.dialect.schemagenerator, entity, 
connection=connection, **kwargs)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 729, in _run_visitor
    element.accept_visitor(visitorcallable(conn, **kwargs))
  File "/usr/lib/python2.4/site-packages/sqlalchemy/schema.py", line 
1266, in accept_visitor
    visitor.visit_metadata(self)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 
798, in visit_metadata
    table.accept_visitor(self)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 2713, 
in accept_visitor
    visitor.visit_table(self)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/ansisql.py", line 
833, in visit_table
    self.execute()
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 1215, in execute
    return self.connection.execute(self.buffer.getvalue())
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 517, in execute
    return Connection.executors[c](self, object, *multiparams, **params)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 532, in execute_text
    self._execute_raw(context)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 581, in _execute_raw
    self._execute(context)
  File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
line 599, in _execute
    raise exceptions.SQLError(context.statement, context.parameters, e)
sqlalchemy.exceptions.SQLError: (DatabaseError) ORA-00942: table or view 
does not exist
 '\nCREATE TABLE tariffa (\n\tid INTEGER NOT NULL, 
\n\tcod_funzione_calcolo VARCHAR(5) NOT NULL, \n\tPRIMARY KEY (id), \n\t 
FOREIGN KEY(cod_funzione_calcolo) REFERENCES funzione_calcolo 
(codice)\n)\n\n' {}


jo ha scritto:
> hi all,
>
> I'm having problems with database.metadata.create_all.
> The code works perfectly with PostgreSQL but with Oracle it 
> doesn't...and it exits with the following error:
>
> ...
>     self._execute_raw(context)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
> line 581, in _execute_raw
>     self._execute(context)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", 
> line 599, in _execute
>     raise exceptions.SQLError(context.statement, context.parameters, e)
> sqlalchemy.exceptions.SQLError: (DatabaseError) ORA-00942: table or view 
> does not exist
>  '\nCREATE TABLE tariffa (\n\tid INTEGER NOT NULL, 
> \n\tcod_funzione_calcolo VARCHAR(5) NOT NULL, \n\tPRIMARY KEY (id), \n\t 
> FOREIGN KEY(cod_funzione_calcolo) REFERENCES funzione_calcolo 
> (codice)\n)\n\n' {}
>
>
> here the source...
> -----------------------------------------------------------------------
> from turbogears                         import database
> from sqlalchemy                         import *
> from sqlalchemy.ext.assignmapper        import assign_mapper
> from sqlalchemy.ext.selectresults       import SelectResultsExt
> database.bind_meta_data()
> session = database.session
> engine  = database.metadata.engine
> context = database.session.context
> tbl = {}
>
> tbl['funzione_calcolo']=Table('funzione_calcolo',database.metadata,
>     Column('codice', Unicode(5),nullable=False,primary_key=True),
>     Column('descrizione', Unicode(200), nullable=False),
>     )
> tbl['tariffa']=Table('tariffa',database.metadata,
>     Column('id', Integer, Sequence('tariffa_seq'), nullable=False, 
> primary_key=True),
>     Column('cod_funzione_calcolo', Unicode(5), nullable=False),
>     
> ForeignKeyConstraint(['cod_funzione_calcolo'],['funzione_calcolo.codice']),
>     )
> database.metadata.create_all(engine)
> -------------------------------------------------------------------------------
>
> what's wrong ?
>
> jo
>
> ps:
> I'm using SA 0.3.10
>
>
> >


--~--~---------~--~----~------------~-------~--~----~
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 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to