2👍
First, you have to change the line, unless your username is a primary key:
my_account = Account.objects.get(username=request.user)
To:
my_account = Account.objects.get(pk=request.user.id)
In this line you try put string (username) to manytomany field:
if obj.username in my_account.following.all():
my_account.following.remove(obj.username)
else:
my_account.following.add(obj.username)
Change it to:
if obj in my_account.following.all():
my_account.following.remove(obj)
else:
my_account.following.add(obj)
This isn’t good practice:
redirect(request.META.get('HTTP_REFERER'))
-1👍
Does it happen when you run server or migrate or migration ?
if it is happened at that time.
-
First real possible solution is that you should delete SQL then reload sql file (For example I use –> db.sqlite3 for saving information into database) then when you enter file that contains in INSTALLED_APPS, you must see migration folder then you need to enter inside of it afterwards as you can see the file which is named init , delete all files there except init (don’t delete it because of package file)
-
Second solution quite complex way is that you can work with database and change one by one through using your intelligence in database.
- [Answered ]-How to use Django ORM to find dangling records?
- [Answered ]-(beginner) First Django Web App – models.py
- [Answered ]-Passing a javascript array to a django view