[Solved] Django database Modify Warning: Did you rename house.houseid to house.id (a BigAutoField)? [y/N] n

1. Problem description

In Django, models Add an order table in the PY file. When migrating through the “py manage.py makemigrations” command, I find that a small black box appears, asking me to rename the ID of the existing table in the database, prompting that adding a non empty “Id” to an existing house table is not allowed; Specific tips are as follows:

2. Problem solving

The following solutions have been tried:

1. Comment out models The code of the new order table in py re executes “py manage.py makemigrations”, and it is found that the above error is still prompted.

2. Someone in stackoverflow has encountered a similar situation (the specific link is here), and the reply solution is as follows:

This might sound dumb but did you perhaps run a find and replace in your project where you replaced id with pid? Django automatically generates primary key fields with the name id not pid. This or perhaps previously you ran a modified version of Django which generated fields named pid instead of id is what I can think happened. As below comment states just edit your migration files and correct them.

The main idea is that this problem is quite outrageous. It is possible that the user-defined primary key in models is ID, but the PID is used in the code;

After checking the code, it is found that one interface with parameters uses “houseid” instead of models After replacing “houseid” with “Id” in the customized primary key “Id” in py, run “py manage.py makemigrations” and find no error.

 1 views.py
 2 
 3 def addToHouseOrder(request, houseid):
 4     """
 5     Users add houses to the order list
 6     :param request:
 7     :param id: houseid
 8     :return:
 9     """
10     if request.method == "GET":
11         currentUser = request.session['username']
12         print(currentUser, houseid)
13         houseResult = House.objects.filter(id=houseid)
14         return HttpResponse(houseid)
15     elif request.method == "POST":
16         pass

Similar Posts: