Cannot Create Table Named "Items" - Already Exists

138 views
Skip to first unread message

Brian Boatright

unread,
Sep 1, 2016, 3:52:11 PM9/1/16
to web2py-users
Is "items" a keyword for Python or Web2py? I'm using mysql and having web2py models file define a new table named "items" but it gives me an error that says the table already exists. 

If I change the name of the table to something like "items2" in the models.py file it works.

The mysql database is empty of tables before this is run and I've confirmed there is no items table before it tries to run the models.py file. I can create a table manually named items so it isn't specific to MySQL database. 

Thanks for any help. 

Richard Vézina

unread,
Sep 1, 2016, 4:14:47 PM9/1/16
to web2py-users
http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=reserved+word#Reserved-keywords

Do you have it in your connection string?

You should be notified that it a mysql reserved word...

If not... Have you change database? New empty database sound like you restart database from scratch... web2py keep track of migration of models you have to migrate=false fake_migrate=true then back to migrate=true to allow web2py to sync with the database...


Richard

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Niphlod

unread,
Sep 1, 2016, 5:11:56 PM9/1/16
to web...@googlegroups.com
"items" isn't a problem for check_reserved.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.

Yoel Benitez Fonseca

unread,
Sep 1, 2016, 5:15:43 PM9/1/16
to web2py
i don't know of "items" but "item" is not a keyword for Python or
Web2py ... i'm using it right now in one of my projects:

db.define_table('item',
# item metadata
Field('provider', 'string', length=100, default=''),
Field('provider_service', 'string'),
Field('pubstatus', 'string', length=10, default='usable'),
Field('embargoed', 'datetime', default=None),
....


2016-09-01 17:11 GMT-04:00 Niphlod <nip...@gmail.com>:
> items isn't a roblem for check_reserved.
--
Yoel Benítez Fonseca
http://redevil.cubava.cu/
$ python -c "import this"

Brian Boatright

unread,
Sep 1, 2016, 5:56:19 PM9/1/16
to web2py-users
I always delete the database in mysql and create it again (no tables). 

Then delete all the files in the database folder.

When it runs again, as far as I know, everything is clean. 

My connection string is just a simple
uri: mysql://root:password@localhost/project

and I don't see anything else in the appconfig.ini or db.py

Brian Boatright

unread,
Sep 1, 2016, 6:42:59 PM9/1/16
to web2py-users
just to be sure it wasn't some odd cache issue or something I missed I created a brand new simple app in the admin called "forum" and created a new model file models.py and created a very basic items table.

# -*- coding: utf-8 -*-
db.define_table('items',
                Field('parentid','integer'),
                Field('itemtypeid','integer'),
                Field('name','string'))

the error is the same as on my other app.

Traceback (most recent call last):
File "C:\dev\web2py\gluon\restricted.py", line 227, in restricted
exec ccode in environment
File "C:/dev/web2py/applications/forum/models/models.py", line 5, in <module>
Field('name','string'))
File "C:\dev\web2py\gluon\packages\dal\pydal\base.py", line 819, in define_table
raise SyntaxError('table already defined: %s' % tablename)
SyntaxError: table already defined: items

I can upload the packaged app but all I did was create a new one and make that models file. it's using all default db stuff (sqlite).
 

Dave S

unread,
Sep 1, 2016, 6:53:54 PM9/1/16
to web2py-users


On your console (or terminal session), do
sqlite3 applications/forum/databases/storage.sqlite
.tables

and see what tables are defined.


/dps

Brian Boatright

unread,
Sep 1, 2016, 7:09:13 PM9/1/16
to web2py-users
I haven't figured out how to get an interactive console on my windows machine BUT I did upload the package to pythonanywhere and used their bash shell. 

The only tables created were the standard authentication tables. 


Dave S

unread,
Sep 1, 2016, 7:20:55 PM9/1/16
to web2py-users


On Thursday, September 1, 2016 at 4:09:13 PM UTC-7, Brian Boatright wrote:
I haven't figured out how to get an interactive console on my windows machine

<windowskey>-<r>command
 
BUT I did upload the package to pythonanywhere and used their bash shell. 

The only tables created were the standard authentication tables. 


Puzzling.

/dps
 

Brian Boatright

unread,
Sep 1, 2016, 7:26:46 PM9/1/16
to web2py-users
indeed!

I'm new to web2py and python. if I knew a bit more I would try to edit the base.py function for define_table that might give some more details. the error stops right on line 819 of base.py. would be good to have self.tables print out as part of the error or even directly on the page.

Brian Boatright

unread,
Sep 1, 2016, 8:20:36 PM9/1/16
to web2py-users
thanks to Yoel pointing out that "item" works I just changed the table name to "item" instead of "items" but I would really like to see this issue fixed or at least explained. it's either a bug or a reserved word that isn't being detected correctly.

Thanks all for the help so far. 

Dave S

unread,
Sep 1, 2016, 8:55:59 PM9/1/16
to web2py-users


On Thursday, September 1, 2016 at 5:20:36 PM UTC-7, Brian Boatright wrote:
thanks to Yoel pointing out that "item" works I just changed the table name to "item" instead of "items" but I would really like to see this issue fixed or at least explained. it's either a bug or a reserved word that isn't being detected correctly.

Thanks all for the help so far. 

I have no trouble manually creating a table called 'items' in my sqlite3 database.

/dps

Brian Boatright

unread,
Sep 1, 2016, 9:46:10 PM9/1/16
to web2py-users
so it's just something in the web2py code base that has a problem with the word "items" as a database table name. 

Dave S

unread,
Sep 2, 2016, 6:02:52 AM9/2/16
to web2py-users


On Thursday, September 1, 2016 at 6:46:10 PM UTC-7, Brian Boatright wrote:
so it's just something in the web2py code base that has a problem with the word "items" as a database table name. 

I can confirm this behavior.  My investigation seems to show that DAL has a  method called "items", and the hasattr() check at base.py#815 picks this up.

/dps


Massimo Di Pierro

unread,
Sep 6, 2016, 10:37:54 AM9/6/16
to web2py-users
yes. Items is a reserved keyword for this reason.

Dave S

unread,
Sep 7, 2016, 3:50:09 AM9/7/16
to web2py-users


On Tuesday, September 6, 2016 at 7:37:54 AM UTC-7, Massimo Di Pierro wrote:
yes. Items is a reserved keyword for this reason.

The trick is knowing which keywords are reserved, before trying to use them and getting an error message  :-)

/dps
Reply all
Reply to author
Forward
0 new messages