Surendar
Surendar

Reputation: 33

<type 'exceptions.SyntaxError'>(Invaild table/column name "Date" is a "All" reserved SQL/NOSQL keyword

db.define_table('Bill',
                Field('Bill_NO', 'integer', requires=IS_NOT_EMPTY()),
                Field('Date', 'date'),
                Field('Customer_ID', requires=IS_NOT_EMPTY()),
                Field('Name', requires=IS_NOT_EMPTY()),
                Field('Address', 'text', length=255),
                Field('Phone', requires=IS_NOT_EMPTY()),
                Field('Item', 'list',  requires=IS_NOT_EMPTY()), Field('Price', 'list`', requires=IS_NOT_EMPTY()),
                Field('Grand_Total', 'double', requires=IS_NOT_EMPTY())
                #auth.signature
               )

I have typed the above code and I got the following error after clicking on db.Bill in models, (Invaild table/column name "Date" is a "All" reserved SQL/NOSQL keyword So help me out to get rid of this error. Thanks.

Upvotes: 2

Views: 420

Answers (2)

Anthony
Anthony

Reputation: 25536

If you want to use Date in your web2py code but don't mind if the database uses an alternative name, you can do:

Field('Date', 'date', rname='bill_date')

In that case, the database will use bill_date as the column name (therefore avoiding the reserved keyword error), but in your web2py code, you can still refer to db.Bill.Date.

Upvotes: 1

JC Borlagdan
JC Borlagdan

Reputation: 3638

Because Date is a datatype in SQL database, if you want to make it as your column name replace it to [Date]

Upvotes: 1

Related Questions