[web2py] postgres error
db.define_table('countries', Field('country_name') ) db.define_table('testing', Field('origin','reference countries',requires=IS_IN_DB(db,'countries.country_name',error_message='Choose origin country')) ) when i try to input testing from database administration, i get this error: insert or update on table "testing" violates foreign key constraint "sea_inquery_origin_fkey" DETAIL: Key (origin)=(0) is not present in table "countries". any idea? i create different tables but get same result. -- --- 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. For more options, visit https://groups.google.com/groups/opt_out.
Re: [web2py] Postgres error
Hi Bruce, G-mail failed to warn me about your answer, so I noticed it only today. Thanks a lot, it worked like a charm. The same code worked in sqlite, but I guess Postgres is more restrictive. Thank you and BR Loreia On Friday, April 27, 2012 4:13:33 PM UTC+2, Bruce Wade wrote: > > (db.block_names.id == db.block_data.block_names_id) > db.block_names.id is an integer > db.block_data.block_names_id is a character varying. > > update db.define_tables("block_data", > Field("block_names_id", "integer", default=None) > > On Fri, Apr 27, 2012 at 5:00 AM, Loreia <...@gmail.com> wrote: > >> Hi, >> >> I define two tables in my application as: >> >> db.define_table( "block_names" >>, Field("block_name" ,default=None) >> ) >> >> db.define_table( "block_data" >>, Field("block_names_id" ,default=None) >>, Field("product_number" ,default=None) >>, Field("product_revision" ,default=None) >>, Field("product_path" ,default=None) >>, Field("branch" ,default=None) >>, Field("bat_file_path" ,default=None) >>, Field("toolbox",default=None) >> ) >> >> I am trying to run following query: >> rows = db((db.block_names.id > 0) >> &(db.block_names.id == >> db.block_data.block_names_id)).select(db.block_names.block_name, >> db.block_data.ALL) >> >> And I get this error: >> File ".../sqr_enumerate_pairs.py", line 77, in EnumeratePairs >> &(db.block_names.id == >> db.block_data.block_names_id)).select(db.block_names.block_name, >> db.block_data.ALL) >> File "/.../web2py/gluon/dal.py", line 7578, in select >> return adapter.select(self.query,fields,attributes) >> File "/.../web2py/gluon/dal.py", line 1315, in select >> rows = response(sql) >> File "/.../web2py/gluon/dal.py", line 1305, in response >> self.execute(sql) >> File "/.../web2py/gluon/dal.py", line 1392, in execute >> return self.log_execute(*a, **b) >> File "/.../web2py/gluon/dal.py", line 1386, in log_execute >> ret = self.cursor.execute(*a, **b) >> ProgrammingError: operator does not exist: integer = character varying at >> character 309 >> HINT: No operator matches the given name and argument type(s). You might >> need to add explicit type casts. >> >> I am using latest 1.99.7 Web2py, latest 9.1.2 Postgres, and latest 2.4.4 >> psycopg2 driver. >> >> Any help is welcomed :-) >> >> BR >> Loreia >> > > > > -- > -- > Regards, > Bruce Wade > http://ca.linkedin.com/in/brucelwade > http://www.wadecybertech.com > http://www.fittraineronline.com - Fitness Personal Trainers Online > http://www.warplydesigned.com > >
Re: [web2py] Postgres error
(db.block_names.id == db.block_data.block_names_id) db.block_names.id is an integer db.block_data.block_names_id is a character varying. update db.define_tables("block_data", Field("block_names_id", "integer", default=None) On Fri, Apr 27, 2012 at 5:00 AM, Loreia wrote: > Hi, > > I define two tables in my application as: > > db.define_table( "block_names" >, Field("block_name" ,default=None) > ) > > db.define_table( "block_data" >, Field("block_names_id" ,default=None) >, Field("product_number" ,default=None) >, Field("product_revision" ,default=None) >, Field("product_path" ,default=None) >, Field("branch" ,default=None) >, Field("bat_file_path" ,default=None) >, Field("toolbox",default=None) > ) > > I am trying to run following query: > rows = db((db.block_names.id > 0) > &(db.block_names.id == > db.block_data.block_names_id)).select(db.block_names.block_name, > db.block_data.ALL) > > And I get this error: > File ".../sqr_enumerate_pairs.py", line 77, in EnumeratePairs > &(db.block_names.id == > db.block_data.block_names_id)).select(db.block_names.block_name, > db.block_data.ALL) > File "/.../web2py/gluon/dal.py", line 7578, in select > return adapter.select(self.query,fields,attributes) > File "/.../web2py/gluon/dal.py", line 1315, in select > rows = response(sql) > File "/.../web2py/gluon/dal.py", line 1305, in response > self.execute(sql) > File "/.../web2py/gluon/dal.py", line 1392, in execute > return self.log_execute(*a, **b) > File "/.../web2py/gluon/dal.py", line 1386, in log_execute > ret = self.cursor.execute(*a, **b) > ProgrammingError: operator does not exist: integer = character varying at > character 309 > HINT: No operator matches the given name and argument type(s). You might > need to add explicit type casts. > > I am using latest 1.99.7 Web2py, latest 9.1.2 Postgres, and latest 2.4.4 > psycopg2 driver. > > Any help is welcomed :-) > > BR > Loreia > -- -- Regards, Bruce Wade http://ca.linkedin.com/in/brucelwade http://www.wadecybertech.com http://www.fittraineronline.com - Fitness Personal Trainers Online http://www.warplydesigned.com
[web2py] Postgres error
Hi, I define two tables in my application as: db.define_table( "block_names" , Field("block_name" ,default=None) ) db.define_table( "block_data" , Field("block_names_id" ,default=None) , Field("product_number" ,default=None) , Field("product_revision" ,default=None) , Field("product_path" ,default=None) , Field("branch" ,default=None) , Field("bat_file_path" ,default=None) , Field("toolbox",default=None) ) I am trying to run following query: rows = db((db.block_names.id > 0) &(db.block_names.id == db.block_data.block_names_id)).select(db.block_names.block_name, db.block_data.ALL) And I get this error: File ".../sqr_enumerate_pairs.py", line 77, in EnumeratePairs &(db.block_names.id == db.block_data.block_names_id)).select(db.block_names.block_name, db.block_data.ALL) File "/.../web2py/gluon/dal.py", line 7578, in select return adapter.select(self.query,fields,attributes) File "/.../web2py/gluon/dal.py", line 1315, in select rows = response(sql) File "/.../web2py/gluon/dal.py", line 1305, in response self.execute(sql) File "/.../web2py/gluon/dal.py", line 1392, in execute return self.log_execute(*a, **b) File "/.../web2py/gluon/dal.py", line 1386, in log_execute ret = self.cursor.execute(*a, **b) ProgrammingError: operator does not exist: integer = character varying at character 309 HINT: No operator matches the given name and argument type(s). You might need to add explicit type casts. I am using latest 1.99.7 Web2py, latest 9.1.2 Postgres, and latest 2.4.4 psycopg2 driver. Any help is welcomed :-) BR Loreia