【发布时间】:2015-09-03 07:10:20
【问题描述】:
我正在尝试将 Stripe 嵌入到自定义配置文件应用程序中,并使用 django-registration 包来注册用户。我需要让用户注册,然后为新用户生成一个 Stripe ID,但出现以下错误:
OperationalError at /accounts/login/
no such table: profiles_userstripe
我的 Profile 应用模型的完整代码如下:
from django.db import models
from django.contrib.auth.models import User
from django.contrib.auth.signals import user_logged_in
from dailydeals.stripe_info import secret_key, publish_key
import stripe
stripe.api_key = secret_key
class UserStripe(models.Model):
user = models.OneToOneField(User)
stripe_id = models.CharField(max_length=120, null=True, blank=True)
phone_number = models.CharField(max_length=120, default='000-000-0000')
def __unicode__(self):
return self.user.username
def CreateStripeID(sender, user, request, **kwargs):
new_id, created = UserStripe.objects.get_or_create(user=user)
if created:
# add users email to stripe and then set stripe id to model
stripe_cust = stripe.Customer.create(email=user.email, description = 'Customer %s was created' \
%(user.username))
print stripe_cust.id
new_id.stripe_id = stripe_cust.id
new_id.save()
else:
print "Stripe has been created %s " %new_id
#print "user logged in %s, %s, %s" %(sender, user, request)
user_logged_in.connect(CreateStripeID)
请指教。
【问题讨论】:
-
您是否尝试过创建迁移并运行它来创建表?
-
是的,我确实做到了...事实上,因为我处于开发模式,所以我删除了几次数据库以确保 Sqlite 没有创建空数据库。此外,我正在使用 django-registration 应用程序的内置模板。当我使用登录时,它工作正常......当我注销时,它显示我在上面发布的错误。
-
什么是完整的回溯?您的配置文件的迁移文件都是什么样的?当你运行
./manage.py showmigrations profiles时会发生什么? -
我不确定它的命令是否与 1.6.8 一起使用...不能在 Windows 上运行。
-
你说得对,Django 迁移(而不是 South)是在 Django 1.7 中添加的,
showmigrations命令是在 1.8 中添加的。
标签: django python-2.7 django-templates stripe-payments