On Tuesday, September 10, 2019 at 2:58:06 PM UTC-7, Steve wrote:
>
> Goodevening,
>
> I am trying to migrate from Sqite to MySQL.
> Unfortunatly when restoring the field in the DB tables i get the following 
> error: 
> <class 'gluon.contrib.pymysql.err.IntegrityError'> (1215, u'Cannot add 
> foreign key constraint')
> location of issue: Field('Insurance',db.insurance,label=T('Insurance')),
>
> When i look this up in google .... this could be caused by  a Field which 
> has the reuirement= Not NULL but has no Default value set.
> I tested this but not able to get passed the error.
>
> *first table with field in db1.py*
>
> db.define_table('insurance',
>                 
> Field('Company',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), 
> label=T('Company')),
>                 Field('Insurance_number','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'),  
> label=T('Insurance Number')),
>                 Field('Street_name', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Street 
> Name')),
>                 Field('House_number','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('House 
> Number')),
>                 Field('Postal_code','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'),label=T('Postal 
> Code')),
>                 Field('City','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('City')),
>                 Field('Region','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Region')),
>                 Field('Country','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), 
> label=T('Country')),
>                 Field('Telephone_number','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Telephone 
> Number')),
>                 Field('Mobile','string', 
> requires=IS_NOT_EMPTY(error_message='cannot be empty!'), label=T('Mobile')),
>                 Field('Email','string', 
> requires=IS_EMAIL(error_message='invalid email! Please fill in a correct 
> e-mail address.'), label=T('Email')),
>                 auth.signature, format='%(Company)s',fake_migrate=True)
>
> *Second table which in a db2.py:*
>
> db.define_table('client',
>                 
> Field('Debtor_nr',requires=IS_NOT_EMPTY(error_message='cannot be empty!'), 
> label=T('Debtor number')),
>                 Field('Insurance',db.insurance,label=T('Insurance')), --> 
> this 
> is where the first issue takes place
>
> Where should i add a default value ? to et this issue fixed
>
> Hope you can help me with this
>
> Steve
>

This page has different diagnoses than you mention:
<URL:
https://www.rathishkumar.in/2016/01/solved-how-to-solve-mysql-error-code.html
>

There, the issue with NULL is that the foreign key can't be NULL if it is 
part of the child table's primary key.

Another way to get the error is to use a different mysql storage engine 
than innodb.

Yet another way is to not have a unique key in the table, but since you're 
using a model file to describe the parent table, the DAL should have 
handled that, and also made sure that the parent and child agree on what 
the key is.

As a first step, use your mysql console or dbclient to display the schema 
used for the insurance table.  (I can't tell you how to do that, because I 
use sqlite and postgres, not mysql, so I know two incantations but they 
probably don't match what you need).

Good luck!

/dps

 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/7eb2aa7f-0d0f-48b3-882d-6837b555cd1b%40googlegroups.com.

Reply via email to