Issues with cpdb - references invalid table

49 views
Skip to first unread message

at

unread,
Nov 28, 2013, 2:58:22 AM11/28/13
to web...@googlegroups.com
Hi,

While migrating data from postgresql to ms-sql-server I am getting following error:

EXCEPTION: could not make a copy of the database
('42000', "[42000] [Microsoft][ODBC SQL Server Driver][SQL Server]Foreign key 'admission_clinic__constraint' references invalid table 'clinic'.")

It is obvious that before referring to table 'clinic' we need to first create it. In our db.py, the order is correct and 'clinic' table definition is prior to the 'admission' table but cpdb is attempting to first create 'admission' table and hence failing.

Any suggestions how it can be fixed? How can we force cpdb to use the same order of tables definition as defined in db.py?

Thanks & Regards,
AT


PS. I am using -f, -F, -y, -Y & -d switches with cpdb.

Alan Etkin

unread,
Dec 1, 2013, 5:34:52 PM12/1/13
to web...@googlegroups.com
Any suggestions how it can be fixed? How can we force cpdb to use the same order of tables definition as defined in db.py?

The copy method loops trough the DAL instance table items. Try this in a console:

>>> for table in db:
>>>    print table._tablename

Does it return the correct order? Also keep in mind that "... Models in the same folder/subfolder are executed in alphabetical order ..." in case you have more than one model file.

at

unread,
Dec 2, 2013, 1:38:51 AM12/2/13
to web...@googlegroups.com

>>> for table in db:
>>>    print table._tablename


returns the correct order, the same as defined in models/db.py, whereas if I add a print statement 'print table' under  loop 'for table in self.db:' in scripts/cpdb.py it returns the list of tables in alphabetic order.

Thanks & Regards

Alan Etkin

unread,
Dec 2, 2013, 11:59:05 AM12/2/13
to web...@googlegroups.com
returns the correct order, the same as defined in models/db.py, whereas if I add a print statement 'print table' under  loop 'for table in self.db:' in scripts/cpdb.py it returns the list of tables in alphabetic order.

I belive this is a problem with the DAL class initialization. If you are running the script from the command line, sql db table definitions will be probably retrieved from database table files, which have, I guess, a different order than the model definitions.

Reply all
Reply to author
Forward
0 new messages