When I click on Users in admin site, it is showing errors. I am not getting points here. Also I did migrations, but it is not working. Please help me out what to do here.
Errors:
OperationalError at /admin/Master/profile/
no such table: Master_profile
Request Method: GET
Request URL: http://localhost:8000/admin/Master/profile/
Django Version: 4.0.4
Exception Type: OperationalError
Exception Value:
no such table: Master_profile
Exception Location: C:\Users\Manoj\AppData\Local\Programs\Python\Python39\lib\site-packages\django\db\backends\sqlite3\base.py, line 477, in execute
Python Executable: C:\Users\Manoj\AppData\Local\Programs\Python\Python39\python.exe
Python Version: 3.9.5
Python Path:
['E:\\Project\\S3_project',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\python39.zip',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\DLLs',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\lib',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39',
'C:\\Users\\Manoj\\AppData\\Roaming\\Python\\Python39\\site-packages',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\win32',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\win32\\lib',
'C:\\Users\\Manoj\\AppData\\Local\\Programs\\Python\\Python39\\lib\\site-packages\\Pythonwin']
Server time: Wed, 27 Apr 2022 06:36:44 0000
models.py:
class Profile(User):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='user_profile')
address = models.TextField(max_length=200,null=False)
contact_number = models.PositiveIntegerField(null=False)
ut=(('Admin','Admin'),('Operator','Operator'),('Ticket generator User','Ticket generator User'),('Inspector','Inspector'),('User 80','User 80'),('Final Inspection','Final Inspection'),('Maintenance','Maintenance'),('Ticket Admin','Ticket Admin'),)
user_type = models.CharField(max_length=200, null=False, choices=ut)
def __str__(self):
return f'{self.user.username} profile'
admin.py:
admin.site.register(Profile)
Templates:
user_show.html:
{% for user in users %}
<tr>
<td><input type="checkbox" /></td>
<td>{{ user.id }}</td>
<td>{{ user.first_name }}</td>
<td>{{ user.user_type }}</td>
<td>{{ user.username }}</td>
<td>{{ user.password }}</td>
<td><a href="/Master/user_edit/{{user.id}}"><span style="color:brown;" ></span></a></p></td>
<td><a href="/Master/user_delete/{{user.id}}"><span style="color:brown;" ></span></a></p></td>
</tr>
{% endfor %}
views.py:
def user_index(request):
users = Profile.objects.all()
return render(request,"Master/user_show.html",{'users':users})
CodePudding user response:
I had Encountered a similar error when I was starting with Django,Which I solved by removing the existing database (db.sqlite3) and deleting the migrations folders of the app. And then re-running python manage.py makemigrations
and then python manage.py migrate
Also check if your app is registered in the settings.py