python - Multiple default values specified for column "id" of the table -


i use run website on laptop , database sqlite, wanted transfer digitalocean , changed database postgresql, when migrate encounters problems.

python 3.4 django 1.8

error

django.db.utils.programmingerror: multiple default values specified column "id" of table "profiles_userprofile" 

my model

class userprofile(models.model):     user = models.onetoonefield(user)     avatar = models.imagefield(blank=true, upload_to=get_image_path, default='/static/image/avatar/male.png')     age = models.integerfield(default=4, validators=[minvaluevalidator(3), maxvaluevalidator(99)]) 

what should do?

try explicitly specifying id field , marking primary key:

class userprofile(models.model):     id = models.bigintegerfield(primary_key = true)     user = models.onetoonefield(user)     avatar = models.imagefield(blank=true, upload_to=get_image_path, default='/static/image/avatar/male.png')     age = models.integerfield(default=4, validators=[minvaluevalidator(3), maxvaluevalidator(99)]) 

django should automatically create sequence field.

it may user foreign key without explicitly defined primary key confusing orm, although that's theory.


Comments

  1. This comment has been removed by the author.

    ReplyDelete
    Replies
    1. Delete everything from the migrations folder (except __init__.py), also delete the .SQLite database file as well. If using PostgreSQL delete database and set it up afresh. Then rerun
      the python manage.py commands;

      python manage.py makemigrations
      python manage.py migrate
      python manage.py runserver

      Delete

Post a Comment

Popular posts from this blog

c# - Where does the .ToList() go in LINQ query result -

Listeners to visualise results of load test in JMeter -

android - CollapsingToolbarLayout: position the ExpandedText programmatically -