【发布时间】:2017-02-15 16:03:19
【问题描述】:
请帮忙!我尝试寻找答案,但我认为这个问题过于具体,无法提供足够通用的解决方案。
我很难准确指出这个错误是什么时候开始的。我现在尝试了太多更改,不知道该站点上次工作的时间。我对此很陌生。并且完全是自学的。我可以向你保证,这将是显而易见的。
尝试迁移时收到此错误:
when attempting to migrate I receive this error:
Apply all migrations: admin, auth, contenttypes, purchase_log, sessions
Running migrations:
Applying purchase_log.0009_auto_20161005_1524...Traceback (most recent call la
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
utility.execute()
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
self.execute(*args, **cmd_options)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
output = self.handle(*args, **options)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
fake_initial=fake_initial,
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_i
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
state = migration.apply(state, schema_editor)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
operation.database_forwards(self.app_label, schema_editor, old_state, projec
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
field,
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
self._remake_table(model, create_fields=[field])
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
self.effective_default(field)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
default = field.get_db_prep_save(default, self.connection)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
return self.target_field.get_db_prep_save(value, connection=connection)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
prepared=False)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
value = self.get_prep_value(value)
File "C:\Users\jdcar\AppData\Local\Programs\Python\Python35-32\lib\site-packag
return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not
我快疯了,不知道从哪里开始!请帮忙!
编辑:这里是 .models.py
from django.db import models
from django.contrib.auth.models import User
class Store(models.Model):
name = models.CharField(max_length=250)
owner = models.ForeignKey(User)
def __str__(self):
return self.name
class Product(models.Model):
type = models.CharField(max_length=250)
owner = models.ForeignKey(User)
def __str__(self):
return self.type
class Receipt(models.Model):
store = models.ForeignKey(Store)
date = models.DateField()
line_items = models.ManyToManyField(Product, through='ReceiptProduct')
owner = models.ForeignKey(User)
def __str__(self):
return self.store.name + ': ' + str(self.date)
class ReceiptProduct(models.Model):
receipt = models.ForeignKey(Receipt)
product = models.ForeignKey(Product)
price = models.FloatField()
sale = models.BooleanField()
description = models.CharField(max_length=500, null=True, blank=True)
owner = models.ForeignKey(User)
def __str__(self):
return self.product.type
编辑:这里是迁移 0009_auto_20161005_1524.py
# -*- coding: utf-8 -*-
# Generated by Django 1.10.1 on 2016-10-05 19:24
from __future__ import unicode_literals
from django.conf import settings
import django.contrib.auth.models
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('purchase_log', '0008_receiptproduct_sale'),
]
operations = [
migrations.AddField(
model_name='product',
name='owner',
field=models.ForeignKey(default=django.contrib.auth.models.User, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='receipt',
name='owner',
field=models.ForeignKey(default=django.contrib.auth.models.User, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='receiptproduct',
name='owner',
field=models.ForeignKey(default=django.contrib.auth.models.User, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
migrations.AddField(
model_name='store',
name='owner',
field=models.ForeignKey(default=django.contrib.auth.models.User, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL),
),
]
【问题讨论】:
-
发布你的
models.py的内容 -
为什么要剪掉错误信息的最后一部分?
not <what>? -
这似乎是从部分屏幕抓取中复制而来的,其中很多内容被截断。请发布整个错误回溯。
-
@JohnGordon 它实际上是整个信息。它只是在那里切断了,这是我困惑的一部分。这确实是整个错误回溯。
-
@Bakuriu 它确实只是在那里切断了。老实说,这是我困惑的一部分。