Django 1.8にプロジェクトがあり、Travis CIを使用し始めていますが、解決できない問題があります。マイグレーションはローカルでは動作しますが、Travis CIでは動作しません
ローカルでテストを実行すると、python manage.py test
で正常に動作し、移行の実行時に問題はありません。しかし、Travisが同じコマンドを実行した場合、1つを除いてすべての移行が適用されます。
エラートレースは以下の通りです:
Traceback (most recent call last):
File "EntHub/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, in execute_from_command_line
utility.execute()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 30, in run_from_argv
super(Command, self).run_from_argv(argv)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/base.py", line 390, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 74, in execute
super(Command, self).execute(*args, **options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/test.py", line 90, in handle
failures = test_runner.run_tests(test_labels)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 210, in run_tests
old_config = self.setup_databases()
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 166, in setup_databases
**kwargs
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/test/runner.py", line 370, in setup_databases
serialize=connection.settings_dict.get("TEST", {}).get("SERIALIZE", True),
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/creation.py", line 368, in create_test_db
test_flush=True,
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/__init__.py", line 120, in call_command
return command.execute(*args, **defaults)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/base.py", line 441, in execute
output = self.handle(*args, **options)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/core/management/commands/migrate.py", line 221, in handle
executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
File "/home/travis/virtualenv/python2.7.9/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/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/migrations/executor.py", line 147, in apply_migration
state = migration.apply(state, schema_editor)
File "/home/travis/virtualenv/python2.7.9/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/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/migrations/operations/fields.py", line 201, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 469, in alter_field
return self._alter_many_to_many(model, old_field, new_field, strict)
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/backends/base/schema.py", line 785, in _alter_many_to_many
old_field.rel.through._meta.get_field(old_field.m2m_field_name()),
File "/home/travis/virtualenv/python2.7.9/lib/python2.7/site-packages/django/db/models/options.py", line 554, in get_field
raise FieldDoesNotExist('%s has no field named %r' % (self.object_name, field_name))
django.core.exceptions.FieldDoesNotExist: Account_following has no field named None
これらは、モデルと移行している:
models.py
from django.db import models
from django.contrib.auth.models import User
# Account
class Account(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
birth = models.DateField(blank=True, null=True)
text = models.TextField(blank=True)
avatar = models.URLField(blank=True)
following = models.ManyToManyField("self", symmetrical=False, related_name="followers", blank=True)
def __unicode__(self):
return unicode(self.user.username)
0001_initial.py(OK )
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
from django.conf import settings
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name='Account',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('birth', models.DateField(blank=True)),
('text', models.TextField(blank=True)),
('avatar', models.URLField(blank=True)),
('user', models.OneToOneField(to=settings.AUTH_USER_MODEL)),
],
),
]
0002_auto_20161116_1512.py(OK)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0001_initial'),
]
operations = [
migrations.AlterField(
model_name='account',
name='birth',
field=models.DateField(null=True, blank=True),
),
]
0003_account_following.py(OK)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0002_auto_20161116_1512'),
]
operations = [
migrations.AddField(
model_name='account',
name='following',
field=models.ManyToManyField(related_name='_account_following_+', to='main.Account', blank=True),
),
]
0004_auto_20170119_1151.pyは(失敗)
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0003_account_following'),
]
operations = [
migrations.AlterField(
model_name='account',
name='following',
field=models.ManyToManyField(related_name='followers', to='main.Account', blank=True),
),
]
私はさらに私のファイル.travis.yml
提供:
language: python
python:
- "2.7"
env:
- DJANGO_VERSION=1.8
services:
- postgresql
addons:
postgresql: "9.3"
install:
- pip install -q Django==$DJANGO_VERSION
- pip install psycopg2
before_script:
- psql -c "CREATE USER enthub WITH PASSWORD 'enthub';" -U postgres
- psql -c "ALTER USER enthub CREATEDB;" -U postgres
script:
- python EntHub/manage.py test --verbosity=2
enthub/enthub
をsettings.py
におけるデータベースの資格情報です。
ありがとうございます。