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
pid. This or perhaps previously you ran a modified version of Django which generated fields named
idis 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
- [Solved] DjangoORM Run python manage.py makemigrations Error: no changes detected
- [Solved] django.db.utils.ProgrammingError: (1146, u”Table” xxx doesn’t exist”)
- Python TypeError: __init__() missing 1 required positional argument: ‘on_delete’
- python Warning: OverflowError: Python int too large to convert to C long
- How to Solve Django Error: No such column: xxx
- [Solved] Django Error: – no such table: main.auth_user__old
- [Solved] Django use search_fields error (in get_lookup_constraint)
- [Solved] Djiango Create Migrations Error: query = query.decode(errors=’replace’) AttributeError: ‘str’ object has no attribute ‘decode’
- Django auth.User.groups: (fields.E304) Reverse accessor for User.groups clashes with reverse
- ImportError: No module named pytz