web2py 2.16.01 legacy databases

62 views
Skip to first unread message

DenesL

unread,
Jan 24, 2018, 5:54:34 PM1/24/18
to web2py-users
Testing web2py 2.16.01 installed from source on Windows 8 with Python 2.7.14

I have two tables on MS SQL Server 2012, one is legacy, the other not:

w2p.define_table('person',
 
Field('name', 'string', length=100, notnull=True),
 
Field('info', 'string', length=100),
  primarykey
=['name']
)

w2p
.define_table('persona',
 
Field('name', 'string', length=100, notnull=True),
 
Field('info', 'string', length=100)
)

The appadmin shows the records for both tables but the legacy anchors to display each record are being incorrectly generated as:


Regards,
Denes

Ovidio Marinho

unread,
Jan 24, 2018, 6:35:07 PM1/24/18
to web...@googlegroups.com
What is the need for you to create a primary key in a field name or char?
look this:
It defines, stores and returns a Table object called "person" containing a field (column) "name". This object can also be accessed via db.person, so you do not need to catch the return value.
id: Notes about the primary key

Do not declare a field called "id", because one is created by web2py anyway. Every table has a field called "id" by default. It is an auto-increment integer field (starting at 1) used for cross-reference and for making every record unique, so "id" is a primary key. (Note: the id counter starting at 1 is back-end specific. For example, this does not apply to the Google App Engine NoSQL.)

Optionally you can define a Field of type='id' and web2py will use this field as auto-increment id field. This is not recommended except when accessing legacy database tables which have a primary key under a different name. With some limitation, you can also use different primary keys using the primarykey parameter. primarykey is explained shortly below.
http://www.web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#id--Notes-about-the-primary-key

a good practice of development is not creating primary keys are named, another element would be important to social security + name ,for example.

Hope this helps.




                   http://itjp.net.br
                     http://itjp.net.br
          Ovidio Marinho Falcao Neto
                 ovid...@gmail.com

                            Brasil
            

--
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.

DenesL

unread,
Jan 25, 2018, 7:46:06 AM1/25/18
to web2py-users
Hi Ovidio,

the issue is that appadmin seems to be generating improper links to display records in legacy databases.
The sample code given to reproduce it, although not from a real scenario is syntactically correct.

Can anyone else reproduce the issue?.

Thanks,
Denes

Ovidio Marinho

unread,
Jan 25, 2018, 9:33:51 AM1/25/18
to web...@googlegroups.com
Be clearer, which databases are you using as a legacy? And what kind of operation do you want to do?

DenesL

unread,
Jan 25, 2018, 10:48:40 AM1/25/18
to web2py-users
MS SQL server 2012 (at the top of my first post) using appadmin to display tables/records.
Clear enough?.

Ovidio Marinho

unread,
Jan 25, 2018, 9:18:21 PM1/25/18
to web...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages