Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for custom primary keys? #607

Open
chthor opened this issue Jan 29, 2020 · 1 comment
Open

Support for custom primary keys? #607

chthor opened this issue Jan 29, 2020 · 1 comment

Comments

@chthor
Copy link

chthor commented Jan 29, 2020

I have an application that requires string primary id keys. Standalone PyDAL would be a perfect solution for me otherwise, but it seems like it assumes an integer autoincrement primary key and won't let me define my own. I.e., I can define my table like so:

db.define_table('pizzas', Field('id', type='string'), Field('radius', type='integer'))

and pydal does not object, but an insert statement with a string id fails:

db.pizzas.insert(id='chicago', radius=12)
ValueError: invalid literal for int() with base 10: 'chicago'

Is there any way around this restriction that would allow me to configure my own id field?

Update: looks like maybe this is a WIP in PR 443. Any update on that?

@valq7711
Copy link
Contributor

Hi! Try this:

db.define_table('pizzas', 
       Field('id', type='string'), 
       Field('radius', type='integer'),
       primarykey = ['id'] # this does the trick
)

It works just fine for me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants