Reputation: 23
Django noob here. Whenever I extend the base User Model, and try to access or edit the new fields, I receive the following error [... table not found].
OperationalError at /admin/users/profile/
no such table: users_profile
Request Method: GET
Request URL: http://127.0.0.1:8000/admin/users/profile/
Django Version: 3.1.2
Exception Type: OperationalError
Exception Value:
no such table: users_profile
Exception Location: /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py, line 413, in execute
Python Executable: /Library/Frameworks/Python.framework/Versions/3.7/bin/python3
Python Version: 3.7.7
Python Path:
['/Users/rexmarkman/Desktop/ComputerScienceIA/newproject',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python37.zip',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/lib-dynload',
'/Users/rexmarkman/Library/Python/3.7/lib/python/site-packages',
'/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages']
Server time: Sun, 30 May 2021 12:52:22 +0000
Im not sure why this is happening as I have ran makemigrations and migrate multiple times. For reference here are my migrations
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('profile_picture', models.ImageField(default='default.jpg', upload_to='profile_pictures')),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
]
Also here is my models.py for further reference
from django.db import models
from django.contrib.auth.models import User
from django.forms import ModelForm
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
profile_picture = models.ImageField(default = 'default.jpg', upload_to = 'profile_pictures')
def __str__(self):
return f'{self.user.username} Profile'
Also worth noting that this issue occurs when attempting to change the profile table in the admin site
Please let me know if you need to know anything else.
Thanks for any help :)
Upvotes: 2
Views: 977
Reputation: 676
Try to delete the migrations
folder from your app and db.sqilte3
file and then retry -:
python manage.py makemigrations
python manage.py migrate
python manage.py createsuperuser
and then retry your error must be solved
Upvotes: 1