1

I'm trying to develop a website for an online store and in my accounts' models.py, I have two models. While table for one model was created successfully, table for my UserStripe model wasn't created and it says:

OperationalError at /admin/accounts/userstripe/
no such table: accounts_userstripe

What should I do ?

My models.py:

from django.db import models
from django.contrib.auth.models import User
from django.conf import settings
import stripe
from localflavor.us.us_states import US_STATES

stripe.api_key = settings.STRIPE_SECRET_KEY


class UserStripe(models.Model):
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete= models.CASCADE)
    stripe_id = models.CharField(max_length=120)

    def __unicode__(self):
        return str(self.stripe_id)


class UserAddress(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete= models.CASCADE)
    address = models.CharField(max_length=120)
    address2 = models.CharField(max_length=120)
    city = models.CharField(max_length=120)
    state = models.CharField(max_length=120, choices=US_STATES)
    country = models.CharField(max_length=120)
    zipcode = models.CharField(max_length=25)
    phone = models.CharField(max_length=120)
    shipping = models.BooleanField(default=True)
    billing = models.BooleanField(default=True)
    timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
    updated = models.DateTimeField(auto_now_add=False, auto_now=True)

    def __unicode__(self):
        return str(self.user.username)

My signals.py:

import stripe
from django.conf import settings
from django.contrib.auth.signals import user_logged_in
from .models import UserStripe

stripe.api_key = settings.STRIPE_SECRET_KEY


def get_or_create_stripe(sender, user, *args, **kwargs):
    try:
        user.userstripe.stripe_id
    except UserStripe.DoesNotExist:
        customer = stripe.Customer.create(
            email = str(user.email),
        )
        new_user_stripe = UserStripe.objects.create(
            user = user,
            stripe_id = customer.id,
            )
    except:
        pass


user_logged_in.connect(get_or_create_stripe)

My apps.py:

from django.apps import AppConfig


class AccountsConfig(AppConfig):
    name = 'accounts'

    def ready(signals):
        import accounts.signals

Is there anything that I'm missing?

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Did you `makemigrations` and `migrate`? Context for when you encountered this error would be helpful – Bash Apr 13 '20 at 12:58
  • Yes I did both of them –  Apr 13 '20 at 12:59
  • @AbrarShahriar show full traceback. – unknown Apr 13 '20 at 13:14
  • 1
    Sometimes apps aren't fully migrated, see https://stackoverflow.com/questions/25771755/django-operationalerror-no-such-table/37799885. Running python manage.py migrate --run-syncdb might help. – Paul Rene Apr 13 '20 at 13:20

0 Answers0