Python “django移民”;LookupError:没有安装应用程序&引用;用于初始数据迁移

Python “django移民”;LookupError:没有安装应用程序&引用;用于初始数据迁移,python,django,django-migrations,Python,Django,Django Migrations,我想使用迁移为用户配置文件提供初始数据。但不知何故,我用来扩展用户模型的应用程序在查找时失败了。UserProfile类模型与auth.User一一相关&与其他应用程序的类模型一一相关。有人有办法解决我的问题吗 python版本:2.7 django版本:1.8.11 以下是进行测试时的回溯: File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/home/pup

我想使用迁移为用户配置文件提供初始数据。但不知何故,我用来扩展用户模型的应用程序在查找时失败了。UserProfile类模型与auth.User一一相关&与其他应用程序的类模型一一相关。有人有办法解决我的问题吗

  • python版本:2.7
  • django版本:1.8.11
以下是进行测试时的回溯:

File "./manage.py", line 10, in <module>
  execute_from_command_line(sys.argv)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 354, in execute_from_command_line
  utility.execute()
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 346, in execute
  self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/core/management/base.py", line 394, in run_from_argv
  self.execute(*args, **cmd_options)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/core/management/base.py", line 445, in execute
  output = self.handle(*args, **options)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 222, in handle
  executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 110, in migrate
  self.apply_migration(states[migration], migration, fake=fake, fake_initial=fake_initial)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/db/migrations/executor.py", line 148, in apply_migration
  state = migration.apply(state, schema_editor)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/db/migrations/migration.py", line 115, in apply
  operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/db/migrations/operations/special.py", line 183, in database_forwards
  self.code(from_state.apps, schema_editor)
File "/home/pupil/Coding/estimator/IBES/ibes_initial_data/migrations/0001_ibes_initial_data_user_profile.py", line 6, in set_home_branch_user
  UserProfile = apps.get_model("users.UserProfile")
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/apps/registry.py", line 202, in get_model
  return self.get_app_config(app_label).get_model(model_name.lower())
File "/home/pupil/.virtualenvs/ibes18/local/lib/python2.7/site-packages/django/apps/registry.py", line 150, in get_app_config
  raise LookupError("No installed app with label '%s'." % app_label)
LookupError: No installed app with label 'users'.

你有一个叫做“用户”的应用程序吗?显示你的已安装应用设置。是的,我在我的已安装应用程序中有一个名为users的应用程序。djnago和python verson?如果你在已安装应用程序中有一个名为users的应用程序,但仍然没有得到它,那么我想基本目录可能设置错误,你是否更改了它?python版本是2.7,django版本为1.8.11&用户应用程序的目录位置与其他应用程序位于同一目录中。关于用户应用程序的其他功能工作正常,但将数据填充到用户模型的初始数据迁移以某种方式失败。
# 0001_initial_user_profile.py
from django.db import migrations


def set_profile_user(apps, schema_editor):
    Branch = apps.get_model("multiple", "Branch")
    UserProfile = apps.get_model("users", "UserProfile")
    User = apps.get_registered_model("auth", "User")
    user = User.objects.get(username="test_user")
    branch = Branch.objects.get(id=1)
    db_alias = schema_editor.connection.alias
    UserProfile.objects.using(db_alias).create(
        user=user, home_branch=branch
    )


class Migration(migrations.Migration):
    dependencies = [
        ("multiple", "0001_initial"),
        ("auth", "0006_require_contenttypes_0002"),
        ("ibes_initial_data", "0001_ibes_initial_data_server")
    ]
    operations = [migrations.RunPython(set_home_branch_user)]


# users/models.py

...
class UserProfile(SynchronizableModel):
    from jobs.models.models_master import Merchant
    user = models.OneToOneField(User, unique=True)
    home_branch = models.ForeignKey(Branch)
    max_jobs = models.PositiveSmallIntegerField(default=1)
    merchant_access = models.ManyToManyField(Merchant)
...

# multiple/models.py

...
class Branch(models.Model):
    name = models.CharField(max_length=100, null=False, blank=False)
    created_by = models.ForeignKey(User)
    modified_by = models.ForeignKey(User)

    def __unicode__(self):
        return self.name
...

# settings.py
INSTALLED_APPS = (
...
    'users',
...
)