mysqlweb2pyweb2py-modules

MySQL with web2py : foreign key constraint failing


I am trying to connect mysql with my web2py app: the home screen is coming, but on registering i get the following error:

<class 'gluon.contrib.pymysql.err.IntegrityError'> (1452, u'Cannot add or update a child row: a foreign key constraint fails (`911_signin`.`auth_membership`, CONSTRAINT `auth_membership_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`) ON DELETE CASCADE)')

Before this i was using sqlite and everything was working fine, and since it is showing error in auth tables i am not able to do anything. (Auth tables are predefined in app, so there must be some mistake in my code, but how can i debug or proceed from here?)

I tried disabling foreign keys temporarily by passing dict(foreign_key_checks=0) to adapter_args, but still i am getting same error.

When i try to transfer data from sqlite to mysql using cpdb.py using:

python cpdb.py -f ../applications/911_signin/databases -y sqlite://storage.sqlite -Y mysql://user:pass@127.0.0.1/db -d ../gluon

i get the following error:

EXCEPTION: could not make a copy of the database
'Cannot resolve reference auth_group in auth_permission definition'

Transferring data is the second priority for now, what can i do about the reference error?


Solution

  • The problem was with custom auth defination, which i was doing after auth.define_tables, which led to referencing a table before it was defined.