Django to_field not working -


i have 2 tables roompricedetails , hoteldetails. roompricedetails has foreign key want point primary key field named hotel_id of hoteldetails. used to_field attribute this, seems going wrong where. shows me error

valueerror: invalid literal int() base 10: 'bmh-1'.

when try add hotel_id 'bmh-1' in roompricedetails. 'bmh-1'is hotel id in hoteldetails. if wrong best way make foreign key point hotel_id field in hoteldetails accept values.

my models:

class roompricedetails(models.model):     room_type = models.charfield(max_length=255, primary_key=true)     hotel = models.foreignkey(hoteldetails, to_field='hotel_id')     price_per_day = models.positiveintegerfield(default=0)  class hoteldetails(models.model):     hotel_id = models.autofield(primary_key=true, db_column='hotel_id')     name = models.charfield(max_length=255)     email = models.charfield(max_length=255)     reg_no = models.charfield(max_length=255)     contact_no = models.charfield(max_length=10)     owner_name = models.charfield(max_length=255)     owner_email = models.charfield(max_length=255)     owner_contact_no = models.charfield(max_length=255)     address = models.charfield(max_length=400)     city = models.charfield(max_length=255)     state = models.charfield(max_length=255)     pincode = models.charfield(max_length=6) 

autofield can hold integer, default django sets auto field.

an integerfield automatically increments according available ids. won’t need use directly; primary key field automatically added model if don’t specify otherwise.

what add primary_key charfield

field.primary_key if true, field primary key model.

in example:

class hoteldetails(models.model):     hotel_id = models.charfield(primary_key=true, db_column='hotel_id', max_length=10) 

having primary key not being integer can decrease db performance


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -