La tête de mon modèle est :
# -*- coding: utf-8 -*-
from django.db import models
from django_th.models.services import Services
class Rss(Services):
"""
Model for RSS Service
"""
url = models.URLField(max_length=255)
trigger = models.ForeignKey('TriggerService')
class Meta:
app_label = 'django_th'
db_table = 'django_th_rss'
def __unicode__(self):
return "%s" % (self.url)
def show(self):
return "Services RSS %s %s" % (self.url, self.trigger)
En exécutant un test de mon code j'obtiens :
(django-trigger-happy)foxmask@foxmask:~/Django-VirtualEnv/django-trigger-happy/django_th$ coverage run manage.py test django_th -v2
Creating test database for alias 'default' ('/home/foxmask/Django-VirtualEnv/django-trigger-happy/django_th/trigger_happy_test.sqlite3')...
Destroying old test database 'default'...
Type 'yes' if you would like to try deleting the test database '/home/foxmask/Django-VirtualEnv/django-trigger-happy/django_th/trigger_happy_test.sqlite3', or 'no' to cancel: yes
Operations to perform:
Synchronize unmigrated apps: debug_toolbar, django_js_reverse
Apply all migrations: sessions, admin, django_th, th_twitter, auth, contenttypes, th_rss, th_pocket
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying django_th.0001_initial... OK
Applying sessions.0001_initial... OK
Applying th_pocket.0001_initial... OK
Applying th_pocket.0002_auto_20150102_1355... OK
Applying th_rss.0001_initial... OK
Applying th_rss.0002_auto_20150102_1355... OK
Applying th_twitter.0001_initial... OK
Applying th_twitter.0002_int_to_biginit... OK
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/foxmask/Django-VirtualEnv/django-trigger-happy/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
utility.execute()
...
return Database.Cursor.execute(self, query, params)
OperationalError: no such table: django_th_rss
Alors qu'un migrate fait :
(django-trigger-happy)foxmask@foxmask:~/Django-VirtualEnv/django-trigger-happy/django_th$ ./manage.py migrate
Operations to perform:
Synchronize unmigrated apps: debug_toolbar, django_js_reverse
Apply all migrations: sessions, admin, django_th, th_twitter, auth, contenttypes, th_rss, th_pocket
Synchronizing apps without migrations:
Creating tables...
Installing custom SQL...
Installing indexes...
Running migrations:
Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
Applying admin.0001_initial... OK
Applying django_th.0001_initial... OK
Applying sessions.0001_initial... OK
Applying th_pocket.0001_initial... OK
Applying th_pocket.0002_auto_20150102_1355... OK
Applying th_rss.0001_initial... OK
Applying th_rss.0002_auto_20150102_1355... OK
Applying th_twitter.0001_initial... OK
Applying th_twitter.0002_int_to_biginit... OK
les scripts de migration :
le 0001 de l'app th_rss incriminée :
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('django_th', '__first__'),
]
operations = [
migrations.CreateModel(
name='Rss',
fields=[
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
('name', models.CharField(max_length=255)),
('status', models.BooleanField(default=False)),
('description', models.CharField(max_length=255)),
('url', models.URLField(max_length=255)),
('trigger', models.ForeignKey(to='django_th.TriggerService')),
],
options={
'db_table': 'django_th_rss',
},
bases=(models.Model,),
),
]
suivi du 0002
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('th_rss', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='rss',
name='trigger',
),
migrations.DeleteModel(
name='Rss',
),
]
edit : Le settings édulcoré des commentaires : (j'ai atteint la limite des 8000 caractères donc tout n'est pas là)
import os
DEBUG = True
TEMPLATE_DEBUG = DEBUG
ALLOWED_HOSTS = ["*"]
BASE_DIR = os.path.dirname(os.path.dirname(__file__))
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR + '/trigger_happy.sqlite3',
'USER': '',
'PASSWORD': '',
'HOST': '',
'PORT': '',
'TEST_NAME': BASE_DIR + '/trigger_happy_test.sqlite3',
}
}
TIME_ZONE = 'Europe/Paris'
LANGUAGE_CODE = 'en'
USE_I18N = True
USE_L10N = True
USE_TZ = True
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'
STATIC_ROOT = os.path.join(BASE_DIR, 'static')
STATIC_URL = '/static/'
STATICFILES_FINDERS = (
'django.contrib.staticfiles.finders.FileSystemFinder',
'django.contrib.staticfiles.finders.AppDirectoriesFinder',
)
ROOT_URLCONF = 'django_th.urls'
WSGI_APPLICATION = 'django_th.wsgi.application'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.admin',
'django_th',
'th_rss',
'pocket',
'th_pocket',
'django_js_reverse',
'th_evernote',
'th_twitter',
'th_readability',
)
TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth',
'django.core.context_processors.request'
)
AUTH_PROFILE_MODULE = 'django_th.UserProfile'
Qu'aurai-je pu omettre ?
J'ai fait un test case avec 3 models tout QQ et je n'ai pas de probleme avec l'exécution des TU (tests unitaires) mais là je ne vois pas ce qui le défrise :/