我刚刚将一个名为“Purchaser”的新模型添加到名为“standard”的应用程序中。我运行makemigrations,一切都是hunky dory然后我尝试运行迁移,我得到以下错误:
Running migrations:
Applying tracking.0002_auto_20180418_1909...Traceback (most recent call last):
File "manage.py", line 21, in <module>
execute_from_command_line(sys.argv)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\migrations\operations\fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\backends\base\schema.py", line 481, in alter_field
new_db_params = new_field.db_parameters(connection=self.connection)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 966, in db_parameters
return {"type": self.db_type(connection), "check": self.db_check(connection)}
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 963, in db_type
return self.target_field.rel_db_type(connection=connection)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 877, in target_field
return self.foreign_related_fields[0]
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 634, in foreign_related_fields
return tuple(rhs_field for lhs_field, rhs_field in self.related_fields if rhs_field)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 621, in related_fields
self._related_fields = self.resolve_related_fields()
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\django\db\models\fields\related.py", line 606, in resolve_related_fields
raise ValueError('Related model %r cannot be resolved' % self.remote_field.model)
ValueError: Related model 'standard.Purchaser' cannot be resolved
以下是买方的模型:
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.core.validators import RegexValidator
from django.core.mail import EmailMultiAlternatives
from django.template import loader
from django.utils.html import strip_tags
from django.conf import settings
from django.contrib.sites.models import Site
from comp.models import ENTITY_TYPE_CHOICES
from django.utils.crypto import get_random_string
TIME_CHOICES = (
(8.0,'8:00 AM'),
(8.5,'8:30 AM'),
(9.0,'9:00 AM'),
(9.5,'9:30 AM'),
(10.0,'10:00 AM'),
(10.5,'10:30 AM'),
(11.0,'11:00 AM'),
(11.5,'11:30 AM'),
(12.0,'12:00 PM'),
(12.5,'12:30 PM'),
(13.0,'1:00 PM'),
(13.5,'1:30 PM'),
(14.0,'2:00 PM'),
(14.5,'2:30 PM'),
(15.0,'3:00 PM'),
(15.5,'3:30 PM'),
(16.0,'4:00 PM'),
(16.5,'4:30 PM'),
(17.0,'5:00 PM'),
(17.5,'5:30 PM'),
)
class Purchaser(models.Model):
user = models.OneToOneField(User, blank=True, null=True, on_delete=models.CASCADE)
#entity = models.ForeignKey('comp.Entity', blank=True, null=True)
company = models.ForeignKey('comp.Company', related_name='company_employee', blank=True, null=True, on_delete=models.SET_NULL)
#brand = models.OneToOneField('comp.Brand', related_name='employee', blank=True, null=True, on_delete=models.CASCADE)
desc = models.TextField(blank=True, null=True)
job_title = models.CharField(max_length=64)
company_name = models.CharField(max_length=64)
company_type = models.IntegerField(choices=ENTITY_TYPE_CHOICES, blank=True, null=True)
time_zone = models.CharField(max_length=64, blank=True, null=True)
phone_regex = RegexValidator(regex=r'^\+?1?\d{9,15}$', message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.")
phone_number = models.CharField(validators=[phone_regex], blank=True, max_length=64)
image = models.ImageField(upload_to='employees', blank=True, null=True)
cover_image = models.ImageField('Cover Image', upload_to='employees', blank=True, null=True, help_text='A 1300 width by 300 height top cover image.')
linkedin_id = models.CharField(max_length=255, blank=True, null=True)
pay_token = models.CharField(max_length=255, blank=True, null=True)
stripe_customer_id = models.CharField(max_length=255, blank=True, null=True)
paid_till_date = models.DateTimeField(blank=True, null=True)
linkedin_url = models.URLField(max_length=255, blank=True, null=True)
facebook_url = models.URLField(max_length=255, blank=True, null=True)
twitter_url = models.URLField(max_length=255, blank=True, null=True)
url = models.URLField(max_length=255, blank=True, null=True)
company_url = models.URLField(max_length=255, blank=True, null=True)
registered = models.BooleanField(default=False)
subscription_current = models.BooleanField(default=False)
paid = models.BooleanField(default=False)
#membership = models.IntegerField(choices=MEMBERSHIP_CHOICES)
coupon = models.CharField(max_length=64, blank=True, null=True)
terms = models.BooleanField(default=True)
invoice_requested = models.BooleanField(default=False)
detail_completed = models.BooleanField(default=False)
categories_completed = models.BooleanField(default=False)
jobs_completed = models.BooleanField(default=False)
education_completed = models.BooleanField(default=False)
boards_completed = models.BooleanField(default=False)
articles_completed = models.BooleanField(default=False)
invite_completed = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
def __str__(self):
return self.user.get_full_name()
def username_email(self):
return self.user.email
def full_name(self):
return self.user.first_name + ' ' + self.user.last_name
def first_name(self):
return self.user.first_name
def last_name(self):
return self.user.last_name
def domain_from_email(self):
email = self.user.email
if 'aol' in email or 'gmail' in email or 'yahoo' in email or 'hotmail' in email or 'outlook' in email or 'live' in email:
return None
else:
return email.split('@')[1]
def company_domain(self):
if self.company_url:
domain = ''
if '//' in self.company_url:
domain = self.company_url.split('//')[1]
if '/' in domain:
domain = domain.split('/', 1)[0]
if 'www.' in domain:
domain = domain.split('www.')[0]
return domain
else:
return self.domain_from_email()
# def url_pretty(self):
# return self.url.split('//', 1)[-1]
def fb_url_pretty(self):
if self.facebook_url:
if 'www' in self.facebook_url:
return self.facebook_url.split('www.', 1)[-1]
return self.facebook_url.split('//', 1)[-1]
def tw_url_pretty(self):
if self.twitter_url:
if 'www' in self.twitter_url:
return self.twitter_url.split('www.', 1)[-1]
return self.twitter_url.split('//', 1)[-1]
def li_url_pretty(self):
if self.linkedin_url:
if 'www' in self.linked_url:
return self.linked_url.split('www.', 1)[-1]
return self.linkedin_url.split('//', 1)[-1]
def entity_type(self):
if self.company:
return self.company.entity_type
else:
return None
def is_exchange_provider(self):
return self.user.groups.filter(name='Exchange Provider').exists()
def is_exchange_startup(self):
return self.user.groups.filter(name='Exchange Startup').exists()
class Meta:
verbose_name = "Person"
ACTION_CHOICES = (
(0,'viewed-profile'),
(1,'contact-click'),
(2,'contact'),
(3,'entity-posted'),
(4,'viewed-entity-feed'),
(5,'report-results-reviewed'),
(6,'entity-bookmarked'),
(7,'entity-connected'),
(8,'entity-note-taken'),
(9,'entity-followed'),
(10,'remove-bookmark'),
(11,'note-edited'),
(12,'entity-unfollowed'),
(13,'survey-module-edited'),
(14,'matching-params-edited'),
(15,'new-match'),
(16,'remove-match'),
(17,'searched'),
(18,'completed-review'),
(19,'survey-module-completed'),
(20,'viewed-article'),
(21,'invited-colleague'),
(22,'analytics-query'),
(23,'viewed-page'),
(24,'viewed-question')
)
# class TempEmployeeEntity(models.Model):
# entity = models.ForeignKey('comp.Entity')
# employee = models.ForeignKey(Employee)
class Transaction(models.Model):
#employee = models.ForeignKey(Purchaser, on_delete=models.CASCADE)
entity = models.ForeignKey('comp.Entity', blank=True, null=True, on_delete=models.SET_NULL)
action = models.IntegerField(choices=ACTION_CHOICES)
desc = models.CharField(max_length=255, blank=True, null=True)
created_at = models.DateTimeField(auto_now_add = True)
updated_at = models.DateTimeField(auto_now = True)
def __str__(self):
try:
if self.entity.name:
return self.get_action_display() + ' ' + self.entity.name
else:
return self.get_action_display()
except:
return self.get_action_display()
class InquiryEmail(models.Model):
name = models.CharField(max_length=255, blank=True, null=True)
email = models.EmailField()
message = models.TextField()
sent = models.BooleanField(default=False)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
variables = {
'name': self.name,
'message': self.message,
'email':self.email,
}
subject = "[Innovator's Edge] Contact"
template = loader.get_template('standard/email/inquiry-email.html')
html_content = template.render(variables)
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [settings.DEFAULT_TO_EMAIL])
if self.site.id == 2:
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [settings.DEFAULT_TO_EMAIL], ['info@insurancethoughtleadership.com'])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
class InviteEmail(models.Model):
#employee = models.ForeignKey(Purchaser, on_delete=models.CASCADE)
email = models.EmailField()
sent = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
context = {
'employee': self.employee,
'site_long_name':settings.SITE_LONG_NAME,
'site_url':settings.SITE_URL,
'reply_email':settings.DEFAULT_TO_EMAIL,
}
subject = 'Invitation To Join ' + settings.SITE_LONG_NAME
template = loader.get_template('standard/email/invite-email.html')
html_content = template.render(context)
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.email])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
class ContactEmail(models.Model):
#employee = models.ForeignKey(Purchaser, on_delete=models.CASCADE)
entity = models.ForeignKey('comp.Entity', on_delete=models.CASCADE)
message = models.TextField()
sent = models.BooleanField(default=False)
site = models.ForeignKey(Site, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
variables = {
'message': self.message,
'employee':self.employee,
'entity':self.entity,
}
subject = '['+settings.SITE_LONG_NAME+'] Contact Request From: '+self.employee.user.get_full_name()
template = loader.get_template('standard/email/contact-email.html')
html_content = template.render(variables)
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.employee.user.email], [settings.DEFAULT_TO_EMAIL])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
NOTIFICATION_CHOICES = (
(0,'Invoice'),
(1,'MMR Request'),
)
class TransactionAlertEmail(models.Model):
#actor = models.ForeignKey(Purchaser, related_name='actor', on_delete=models.CASCADE)
actee = models.ForeignKey('comp.entity', related_name='actee', blank=True, null=True, on_delete=models.SET_NULL)
alert_type = models.IntegerField(choices=NOTIFICATION_CHOICES)
actor_type_name = models.CharField(max_length=128)
actee_type_name = models.CharField(max_length=128, blank=True, null=True)
sent = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
title = self.get_alert_type_display() + ' Notification'
variables = {
'actor': self.actor,
'actee': self.actee,
'actor_type_name':self.actor_type_name,
'alert_type':self.alert_type,
'actee_type_name':self.actee_type_name,
'alert_display':self.get_alert_type_display(),
'temp_static_url':'https://'+settings.AWS_S3_CUSTOM_DOMAIN+'/static',
'host':settings.HOST,
}
subject = "[Innovator's Edge] "+title
template = loader.get_template('standard/email/info-alert-email.html')
html_content = template.render(variables)
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, ['info@insurancethoughtleadership.com'])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
class WelcomeEmail(models.Model):
#employee = models.ForeignKey(Purchaser, on_delete=models.CASCADE)
sent = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
print('sending email')
variables = {
'employee': self.employee,
'temp_static_url':'https://'+settings.AWS_S3_CUSTOM_DOMAIN+'/static',
'host':settings.HOST,
}
subject = 'Welcome to '+settings.SITE_LONG_NAME
template = loader.get_template('standard/email/welcome-email.html')
html_content = template.render(variables)
text_content = strip_tags(html_content)
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [self.employee.user.email])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
class ResetPasswordEmail(models.Model):
#employee = models.ForeignKey(Purchaser, on_delete=models.CASCADE)
request_token = models.CharField(max_length=32,default=get_random_string(length=32), unique=True)
sent = models.BooleanField(default=False)
valid_date = models.DateTimeField()
redeemed = models.BooleanField(default=False)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now = True)
def send(self):
variables = {
'request_token': self.request_token,
'temp_static_url':'https://'+settings.AWS_S3_CUSTOM_DOMAIN+'/static',
'host':settings.HOST,
}
subject = 'Reset Your Password'
template = loader.get_template('standard/email/forgot-password-email.html')
html_content = template.render(variables)
text_content = strip_tags(html_content)
to_email = self.employee.user.email
msg = EmailMultiAlternatives(subject, text_content, settings.DEFAULT_FROM_EMAIL, [to_email])
msg.attach_alternative(html_content, "text/html")
msg.send()
self.sent = True
self.save()
以下是添加它的迁移:
# Generated by Django 2.0.2 on 2018-04-19 02:09
from django.conf import settings
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('for', '0020_auto_20180418_1909'),
('match', '0013_auto_20180418_1909'),
('direct', '0006_auto_20180418_1909'),
('comp', '0074_auto_20180305_1740'),
('track', '0002_auto_20180418_1909'),
('even', '0040_auto_20180418_1909'),
('standard', '0037_auto_20180404_2012'),
]
operations = [
migrations.CreateModel(
name='Purchaser',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('desc', models.TextField(blank=True, null=True)),
('job_title', models.CharField(max_length=64)),
('company_name', models.CharField(max_length=64)),
('company_type', models.IntegerField(blank=True, choices=[(0, 'Startup/Innovator/Insurtech'), (1, 'Provider'), (2, 'Accelerator'), (3, 'Incubator'), (4, 'Rating_agency'), (5, 'Carrier'), (6, 'Regulator'), (7, 'News Source'), (8, 'Trade Association'), (9, 'Reinsurer'), (10, 'TPA'), (11, 'VC'), (12, 'Agent/Broker'), (13, 'Advisory'), (14, 'Consultancy'), (15, 'Investor'), (16, 'person'), (17, 'Other'), (18, 'Technology Provider'), (19, 'Education & Training')], null=True)),
('time_zone', models.CharField(blank=True, max_length=64, null=True)),
('phone_number', models.CharField(blank=True, max_length=64, validators=[django.core.validators.RegexValidator(message="Phone number must be entered in the format: '+999999999'. Up to 15 digits allowed.", regex='^\\+?1?\\d{9,15}$')])),
('image', models.ImageField(blank=True, null=True, upload_to='employees')),
('cover_image', models.ImageField(blank=True, help_text='A 1300 width by 300 height top cover image.', null=True, upload_to='employees', verbose_name='Cover Image')),
('linkedin_id', models.CharField(blank=True, max_length=255, null=True)),
('pay_token', models.CharField(blank=True, max_length=255, null=True)),
('stripe_customer_id', models.CharField(blank=True, max_length=255, null=True)),
('paid_till_date', models.DateTimeField(blank=True, null=True)),
('linkedin_url', models.URLField(blank=True, max_length=255, null=True)),
('facebook_url', models.URLField(blank=True, max_length=255, null=True)),
('twitter_url', models.URLField(blank=True, max_length=255, null=True)),
('url', models.URLField(blank=True, max_length=255, null=True)),
('company_url', models.URLField(blank=True, max_length=255, null=True)),
('registered', models.BooleanField(default=False)),
('subscription_current', models.BooleanField(default=False)),
('paid', models.BooleanField(default=False)),
('coupon', models.CharField(blank=True, max_length=64, null=True)),
('terms', models.BooleanField(default=True)),
('invoice_requested', models.BooleanField(default=False)),
('detail_completed', models.BooleanField(default=False)),
('categories_completed', models.BooleanField(default=False)),
('jobs_completed', models.BooleanField(default=False)),
('education_completed', models.BooleanField(default=False)),
('boards_completed', models.BooleanField(default=False)),
('articles_completed', models.BooleanField(default=False)),
('invite_completed', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('updated_at', models.DateTimeField(auto_now=True)),
('company', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='company_employee', to='comp.Company')),
('user', models.OneToOneField(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Person',
},
),
migrations.RemoveField(
model_name='employ',
name='brand',
),
migrations.RemoveField(
model_name='employ',
name='company',
),
migrations.RemoveField(
model_name='employ',
name='user',
),
migrations.AlterField(
model_name='contact',
name='employee',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='cstandard.Purchaser'),
),
migrations.AlterField(
model_name='invite',
name='employee',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
),
migrations.AlterField(
model_name='resetpassemail',
name='employee',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
),
migrations.AlterField(
model_name='resetpassdemail',
name='request_token',
field=models.CharField(default='jN1D4G0qKCpTexaJWhHhil8qAobmzdu8', max_length=32, unique=True),
),
migrations.AlterField(
model_name='transact',
name='employee',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
),
migrations.AlterField(
model_name='transactalertemail',
name='actor',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='actor', to='stanndard.Purchaser'),
),
migrations.AlterField(
model_name='welcomeem',
name='employee',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='standard.Purchaser'),
),
migrations.DeleteModel(
name='Employ',
),
]
我尝试过基于互联网搜索的内容: 在迁移中添加和删除auth_user_model, 更改设置中的应用顺序 有谁看到这个问题?这让我发疯了。
提前致谢。