如何使用manage.py和命令行从数据库中删除所有表?有没有办法用适当的参数执行manage.py,所以我可以从.NET应用程序执行它?
Python 3,Django 1.8.5,Postgres
我有一个Sites一直运作良好的模型.我最近尝试添加字段,airport_code和迁移数据.
class Site(BaseModel):
objects = SiteManager()
name = models.CharField(max_length=200, unique=True)
domain = models.CharField(max_length=200, unique=True)
weather = models.CharField(max_length=10)
nearby_sites = models.ManyToManyField('self', symmetrical=False, blank=True)
users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True)
facebook = models.URLField(max_length=200)
twitter = models.URLField(max_length=200)
header_override = models.TextField(blank=True)
email_header_override = models.TextField(blank=True)
timely_site_tag_id = models.IntegerField()
timely_featured_tag_id = models.IntegerField()
timely_domain = models.CharField(max_length=255)
sitemap_public_id = models.CharField(max_length=255)
state = models.CharField(max_length=24)
airport_code = JSONField()
Run Code Online (Sandbox Code Playgroud)
但是,当我跑的时候我遇到makemigrations了一个错误:
django.db.utils.ProgrammingError: column sites_site.airport_code does not exist
LINE 1: ..._site"."sitemap_public_id", "sites_site"."state", "sites_sit...
当然,这没有意义,因为当我试图在迁移中创建它时,该列显然不存在.
我已经看到很多关于Stack Overflow上的这个错误的问题没有得到解答,或者有一个解决方案来手动创建迁移文件,或者销毁和重建数据库.这不是一个好的解决方案.
我知道以前有人问过这个问题,但就我的情况而言,我似乎无法弄清楚为什么会抛出这个问题
当我尝试运行我的计算时,我的控制台给出了这个错误:
ValueError: invalid literal for int() with base 10: ''
它说它来自
File "/var/sites/live_mbpathways/moneybroker/apps/investments/ajax.py", line 30, in calc_cdic
investments = Investment.objects.all().filter(plan = plan, financial_institution=fiid, maturity_date__gte = now).order_by('maturity_date').exclude(id=investment_id)
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会发生这种情况?
这是我的 ajax.py 代码所在的位置:
@login_required
@moneybroker_auth
@csrf_exempt
def calc_cdic(request, plan, investment_id=None, *args, **kwargs):
from investments.models import Investment
from financial_institutions.models import FinancialInstitution
from profiles.models import Profile
from plans.models import Plan
from datetime import datetime
now = datetime.now()
json = {}
data = request.POST
if request.is_ajax():
total = 0
fiid = data.get('financial_institution')
amt = data.get('amount') …Run Code Online (Sandbox Code Playgroud) django ×3
ajax ×1
django-admin ×1
django-views ×1
mysql ×1
postgresql ×1
python ×1
python-3.x ×1