Django2.0.7 TypeError: Model instances without primary key value are unhashable












-1















I am trying to migrate the models that were generated for me via python manage.py inspectdb. I tried python manage.py makemigrations and got this error:




SystemCheckError: System check identified some issues:

ERRORS:

Users.DjangoContentType: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.




So I went into my file and changed this model:
enter image description here



To this:
enter image description here



and when I run python manage.py makemigrations and python manage.py migrate and I get this error:



enter image description here



Any idea what I should do/what this means?



This is my pip freeze output:



certifi==2018.10.15
Django==2.0.7
mysqlclient==1.3.13
pytz==2018.7









share|improve this question























  • just remove the id field from your model. because its already present and its primary key

    – ruddra
    Nov 24 '18 at 18:27











  • Then I get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:29













  • Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

    – ivissani
    Nov 24 '18 at 22:06













  • The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

    – ivissani
    Nov 24 '18 at 22:11











  • Don't post pictures of text.

    – Daniel Roseman
    Nov 24 '18 at 22:13
















-1















I am trying to migrate the models that were generated for me via python manage.py inspectdb. I tried python manage.py makemigrations and got this error:




SystemCheckError: System check identified some issues:

ERRORS:

Users.DjangoContentType: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.




So I went into my file and changed this model:
enter image description here



To this:
enter image description here



and when I run python manage.py makemigrations and python manage.py migrate and I get this error:



enter image description here



Any idea what I should do/what this means?



This is my pip freeze output:



certifi==2018.10.15
Django==2.0.7
mysqlclient==1.3.13
pytz==2018.7









share|improve this question























  • just remove the id field from your model. because its already present and its primary key

    – ruddra
    Nov 24 '18 at 18:27











  • Then I get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:29













  • Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

    – ivissani
    Nov 24 '18 at 22:06













  • The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

    – ivissani
    Nov 24 '18 at 22:11











  • Don't post pictures of text.

    – Daniel Roseman
    Nov 24 '18 at 22:13














-1












-1








-1








I am trying to migrate the models that were generated for me via python manage.py inspectdb. I tried python manage.py makemigrations and got this error:




SystemCheckError: System check identified some issues:

ERRORS:

Users.DjangoContentType: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.




So I went into my file and changed this model:
enter image description here



To this:
enter image description here



and when I run python manage.py makemigrations and python manage.py migrate and I get this error:



enter image description here



Any idea what I should do/what this means?



This is my pip freeze output:



certifi==2018.10.15
Django==2.0.7
mysqlclient==1.3.13
pytz==2018.7









share|improve this question














I am trying to migrate the models that were generated for me via python manage.py inspectdb. I tried python manage.py makemigrations and got this error:




SystemCheckError: System check identified some issues:

ERRORS:

Users.DjangoContentType: (models.E004) 'id' can only be used as a field name if the field also sets 'primary_key=True'.




So I went into my file and changed this model:
enter image description here



To this:
enter image description here



and when I run python manage.py makemigrations and python manage.py migrate and I get this error:



enter image description here



Any idea what I should do/what this means?



This is my pip freeze output:



certifi==2018.10.15
Django==2.0.7
mysqlclient==1.3.13
pytz==2018.7






django python-3.x django-models






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 24 '18 at 18:15









Joel CastroJoel Castro

517




517













  • just remove the id field from your model. because its already present and its primary key

    – ruddra
    Nov 24 '18 at 18:27











  • Then I get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:29













  • Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

    – ivissani
    Nov 24 '18 at 22:06













  • The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

    – ivissani
    Nov 24 '18 at 22:11











  • Don't post pictures of text.

    – Daniel Roseman
    Nov 24 '18 at 22:13



















  • just remove the id field from your model. because its already present and its primary key

    – ruddra
    Nov 24 '18 at 18:27











  • Then I get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:29













  • Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

    – ivissani
    Nov 24 '18 at 22:06













  • The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

    – ivissani
    Nov 24 '18 at 22:11











  • Don't post pictures of text.

    – Daniel Roseman
    Nov 24 '18 at 22:13

















just remove the id field from your model. because its already present and its primary key

– ruddra
Nov 24 '18 at 18:27





just remove the id field from your model. because its already present and its primary key

– ruddra
Nov 24 '18 at 18:27













Then I get this error: TypeError: Model instances without primary key value are unhashable

– Joel Castro
Nov 24 '18 at 18:29







Then I get this error: TypeError: Model instances without primary key value are unhashable

– Joel Castro
Nov 24 '18 at 18:29















Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

– ivissani
Nov 24 '18 at 22:06







Why are you including DjangoContentType as part of your models? I’m quite sure you shouldn't as it is part of the content_types application

– ivissani
Nov 24 '18 at 22:06















The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

– ivissani
Nov 24 '18 at 22:11





The ContentType model is used by Django to track the models in te installed apps in a Django project. It is automatically populated by Django and you should not need to mess around with it in most cases

– ivissani
Nov 24 '18 at 22:11













Don't post pictures of text.

– Daniel Roseman
Nov 24 '18 at 22:13





Don't post pictures of text.

– Daniel Roseman
Nov 24 '18 at 22:13












2 Answers
2






active

oldest

votes


















0














ID is an implicitly declared field in django. You dont need to add it in list of model fields. Django autogenerates ID for you.




An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields.




https://docs.djangoproject.com/en/2.1/topics/db/models/






share|improve this answer
























  • yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:48











  • Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

    – Nithin K
    Nov 25 '18 at 10:13











  • I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

    – Joel Castro
    Nov 25 '18 at 16:11











  • Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

    – Nithin K
    Nov 27 '18 at 13:11





















0














So I dropped my database and reinitialized it, and all the steps that I initially took worked... somehow. Still can't explain why






share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461074%2fdjango2-0-7-typeerror-model-instances-without-primary-key-value-are-unhashable%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    ID is an implicitly declared field in django. You dont need to add it in list of model fields. Django autogenerates ID for you.




    An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields.




    https://docs.djangoproject.com/en/2.1/topics/db/models/






    share|improve this answer
























    • yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

      – Joel Castro
      Nov 24 '18 at 18:48











    • Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

      – Nithin K
      Nov 25 '18 at 10:13











    • I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

      – Joel Castro
      Nov 25 '18 at 16:11











    • Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

      – Nithin K
      Nov 27 '18 at 13:11


















    0














    ID is an implicitly declared field in django. You dont need to add it in list of model fields. Django autogenerates ID for you.




    An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields.




    https://docs.djangoproject.com/en/2.1/topics/db/models/






    share|improve this answer
























    • yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

      – Joel Castro
      Nov 24 '18 at 18:48











    • Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

      – Nithin K
      Nov 25 '18 at 10:13











    • I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

      – Joel Castro
      Nov 25 '18 at 16:11











    • Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

      – Nithin K
      Nov 27 '18 at 13:11
















    0












    0








    0







    ID is an implicitly declared field in django. You dont need to add it in list of model fields. Django autogenerates ID for you.




    An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields.




    https://docs.djangoproject.com/en/2.1/topics/db/models/






    share|improve this answer













    ID is an implicitly declared field in django. You dont need to add it in list of model fields. Django autogenerates ID for you.




    An id field is added automatically, but this behavior can be overridden. See Automatic primary key fields.




    https://docs.djangoproject.com/en/2.1/topics/db/models/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Nov 24 '18 at 18:32









    Nithin KNithin K

    1




    1













    • yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

      – Joel Castro
      Nov 24 '18 at 18:48











    • Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

      – Nithin K
      Nov 25 '18 at 10:13











    • I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

      – Joel Castro
      Nov 25 '18 at 16:11











    • Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

      – Nithin K
      Nov 27 '18 at 13:11





















    • yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

      – Joel Castro
      Nov 24 '18 at 18:48











    • Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

      – Nithin K
      Nov 25 '18 at 10:13











    • I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

      – Joel Castro
      Nov 25 '18 at 16:11











    • Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

      – Nithin K
      Nov 27 '18 at 13:11



















    yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:48





    yes, but when I remove those fields and get this error: TypeError: Model instances without primary key value are unhashable

    – Joel Castro
    Nov 24 '18 at 18:48













    Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

    – Nithin K
    Nov 25 '18 at 10:13





    Is there an already existing table in your db called django_content_type ? Which DB you are using ? I think you shouldn''t be using managed=False if there is no existing table that you want to manage.

    – Nithin K
    Nov 25 '18 at 10:13













    I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

    – Joel Castro
    Nov 25 '18 at 16:11





    I'm using mysql, and when I initially did python inspectdb and then python manage.py makemigrations and then python manage.py migrate, I got this error: django.db.utils.ProgrammingError: (1146, "Table 'mydb.django_content_type' doesn't exist") so I manually added the table to my database;

    – Joel Castro
    Nov 25 '18 at 16:11













    Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

    – Nithin K
    Nov 27 '18 at 13:11







    Please delete all the tables, remove meta classes, Run migrations using python manage.py migrate <appname> See what error it is giving

    – Nithin K
    Nov 27 '18 at 13:11















    0














    So I dropped my database and reinitialized it, and all the steps that I initially took worked... somehow. Still can't explain why






    share|improve this answer




























      0














      So I dropped my database and reinitialized it, and all the steps that I initially took worked... somehow. Still can't explain why






      share|improve this answer


























        0












        0








        0







        So I dropped my database and reinitialized it, and all the steps that I initially took worked... somehow. Still can't explain why






        share|improve this answer













        So I dropped my database and reinitialized it, and all the steps that I initially took worked... somehow. Still can't explain why







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 27 '18 at 22:32









        Joel CastroJoel Castro

        517




        517






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53461074%2fdjango2-0-7-typeerror-model-instances-without-primary-key-value-are-unhashable%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            404 Error Contact Form 7 ajax form submitting

            How to know if a Active Directory user can login interactively

            TypeError: fit_transform() missing 1 required positional argument: 'X'