我得到了一个奇怪的错误,来自Python的peewee模块,我无法解决,有任何想法吗?我基本上想要拥有一个包含多个公司的批次。我为每个批次创建一个实例,并将其中所有的公司分配给该批次的行ID。
跟踪
Traceback (most recent call last):
File "app.py", line 16, in <module>
import models
File "/Users/wyssuser/Desktop/dscraper/models.py", line 10, in <module>
class Batch(Model):
File "/Library/Python/2.7/site-packages/peewee.py", line 3647, in __new__
cls._meta.prepared()
File "/Library/Python/2.7/site-packages/peewee.py", line 3497, in prepared
field = self.fields[item.lstrip('-')]
KeyError: 'i'
models.py
from datetime import datetime
from flask.ext.bcrypt import generate_password_hash
from flask.ext.login import UserMixin
from peewee import *
DATABASE = SqliteDatabase('engineering.db')
class Batch(Model):
initial_contact_date = DateTimeField(formats="%m-%d-%Y")
class Meta:
database = DATABASE
order_by = ('initial_contact_date')
@classmethod
def create_batch(cls, initial_contact_date):
try:
with DATABASE.transaction():
cls.create(
initial_contact_date=datetime.now
)
print 'Created batch!'
except IntegrityError:
print 'Whoops, there was an error!'
class Company(Model):
batch_id = ForeignKeyField(rel_model=Batch, related_name='companies')
company_name = CharField()
website = CharField(unique=True)
email_address = CharField()
scraped_on = DateTimeField(formats="%m-%d-%Y")
have_contacted = BooleanField(default=False)
current_pipeline_phase = IntegerField(default=0)
day_0_message_id = IntegerField()
day_0_response = IntegerField()
day_0_sent = DateTimeField()
day_5_message_id = IntegerField()
day_5_response = IntegerField()
day_5_sent = DateTimeField()
day_35_message_id = IntegerField()
day_35_response = IntegerField()
day_35_sent = DateTimeField()
day_125_message_id = IntegerField()
day_125_response = IntegerField()
day_125_sent = DateTimeField()
sector = CharField()
class Meta:
database = DATABASE
order_by = ('have_contacted', 'current_pipeline_phase')
@classmethod
def create_company(cls, company_name, website, email_address):
try:
with DATABASE.transaction():
cls.create(company_name=company_name, website=website, email_address=email_address, scraped_on=datetime.now)
print 'Saved {}'.format(company_name)
except IntegrityError:
print '{} already exists in the database'.format(company_name)
def initialize():
DATABASE.connect()
DATABASE.create_tables([Batch, Company, User],safe=True)
DATABASE.close()