Your model deletes the records and recreates them every time the model runs. This is not such a good idea for testing. Furthermore, it seems to retain the first product, but deletes the referenced keys. Your table ids are not reset to zero, so your first product will probably have missing keys for tag.
Anyhow, here are two suggestions: You can use truncate() rather than delete to empty the tables. Only insert the test records when the database is empty. So insert these lines under your table define statements. Run model once and then comment out: db.product.truncate() db.tag.truncate() Afterwards use the other code to recreate the records only once: if db(db.product.id>0).count() == 0: a = db.tag.insert(name='red') b = db.tag.insert(name='green') c = db.tag.insert(name='blue') db.product.insert(name='Toy Car', tags=[a, b, c]) db.product.insert(name='Toy Boat', tags=[a]) On Sunday, 19 July 2020 01:46:53 UTC+1, P Page-McCaw wrote: > > I am having trouble getting list:reference to work. I have made a tester > app where db.py is: > > db.define_table('tag', > Field('name'), > format='%(name)s') > > db.define_table('product', > Field('name'), > Field('tags', 'list:reference tag')) > > #this isn't necessary for the error, but things were getting out of hand > if db(db.product.id>0).count() != 0: > db(db.tag.id > 0).delete() > db(db.product.id > 1).delete() > > a = db.tag.insert(name='red') > b = db.tag.insert(name='green') > c = db.tag.insert(name='blue') > db.product.insert(name='Toy Car', tags=[a, b, c]) > db.product.insert(name='Toy Boat', tags=[a]) > > That part all seems to work and I get a correct database when I look in > the Admin interface. This is from the manual. > Then in the Database Administration interface, I create a new Product "Toy > Truck" and select say "Green". But when I click submit, I get "Value not in > database". If I try to add a new color to tag, the tag does not appear in > the selection field when I then make a new product. I have similar problems > in my own views, but figure if I can't get this... > -- 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/db7b89b4-28d8-411e-9ca1-c63371c04009o%40googlegroups.com.