kamcoder
kamcoder

Reputation: 75

OperationalError at /admin/accounts/picture/ no such table: accounts_picture

Keep on getting the error below

This is occurring after making migrations.

OperationalError at /admin/accounts/picture/
no such table: accounts_picture

def get_image_filename(instance,filename):
    id = instance.product.id
    return "picture_image/%s" % (id)

def path_and_rename(instance, filename):
    upload_to = 'images'
    ext = filename.split('.'[-1])
    if instance.pk:
        filename = '{}.{}'.format(instance.pk, ext)
    else:
        filename = '{}.{}'.format(uuid4().hex, ext)
    return os.path.join(upload_to, filename)

class Picture(models.Model):
    product_pic = models.ImageField(null=True, blank=True,upload_to=path_and_rename)
    product = models.ForeignKey(Product, null=True, on_delete=models.SET_NULL )
    date_created = models.DateTimeField(auto_now_add=True, null=True)

This error is appearing when trying to access my pictures model on admin.

Is there a way of resolving this?





User = get_user_model()

class UserAdmin(BaseUserAdmin):
    # The forms to add and change user instances
    form = UserAdminChangeForm
    add_form = UserAdminCreationForm

    # The fields to be used in displaying the User model.
    # These override the definitions on the base UserAdmin
    # that reference specific fields on auth.User.
    list_display = ('email', 'admin')
    list_filter = ('admin','staff','active')
    fieldsets = (
        (None, {'fields': ('email', 'password')}),
        ('Personal info', {'fields': ()}),
        ('Permissions', {'fields': ('admin','staff','active')}),
    )
    # add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
    # overrides get_fieldsets to use this attribute when creating a user.
    add_fieldsets = (
        (None, {
            'classes': ('wide',),
            'fields': ('email', 'password1', 'password2')}
        ),
    )
    search_fields = ('email',)
    ordering = ('email',)
    filter_horizontal = ()


admin.site.register(User,UserAdmin)
admin.site.unregister(Group)

@admin.register(Profile, Tag, Product, Order, Address,Picture)
class ViewAdmin(ImportExportModelAdmin):
    pass

See above for admin.py I believe there could be a problem with my admin.py.

Upvotes: 0

Views: 486

Answers (1)

Sagar mochi
Sagar mochi

Reputation: 21

you need to run python ./manage.py makemigrations command first and then -python ./manage.py migrate after that I hope the problem resolves then

if the problem persists then delete all the migrations you have applied so far in that app and rerun the above 2 commands...

Upvotes: 2

Related Questions