Sto eseguendo un test dell'unità utilizzando il framework Django e ottenere questo errore.ProgrammingError: (1146, "Table 'test_ <DB>. <TABLE>" inesistente ") durante l'esecuzione dell'unità test per Django
L'esecuzione del codice effettivo non presenta questo problema, l'esecuzione dei test dell'unità crea un database di test al volo quindi ho il sospetto che il problema si trovi lì.
Il codice che genera l'errore si presenta così
member = Member.objects.get(email=email_address)
e il modello si presenta come
class Member(models.Model):
member_id = models.IntegerField(primary_key=True)
created_on = models.DateTimeField(editable=False, default=datetime.datetime.utcnow())
flags = models.IntegerField(default=0)
email = models.CharField(max_length=150, blank=True)
phone = models.CharField(max_length=150, blank=True)
country_iso = models.CharField(max_length=6, blank=True)
location_id = models.IntegerField(null=True, blank=True)
facebook_uid = models.IntegerField(null=True, blank=True)
utc_offset = models.IntegerField(null=True, blank=True)
tokens = models.CharField(max_length=3000, blank=True)
class Meta:
db_table = u'member'
non c'è niente di troppo strano non riesco a vedere.
l'utente che esegue il test ha le stesse autorizzazioni per il server di database come l'utente che gestisce il sito
questo è Django 1.1 su MariaDB in esecuzione su OSX
MJ-2:mysite Marsh$ python manage.py test sitecoming
Creating test database...
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table djangodblog_errorbatch
Creating table djangodblog_error
Installing index for djangodblog.ErrorBatch model
Installing index for djangodblog.Error model
E
======================================================================
ERROR: test_index (mysite.sitecoming.tests.SiteComingTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/Marsh/Development/deal/src/mysite/sitecoming/tests.py", line 19, in test_index
response = c.post('/submit', {'email':'[email protected]'})
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/test/client.py", line 313, in post
response = self.request(**r)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/core/handlers/base.py", line 92, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Users/Marsh/Development/deal/src/mysite/sitecoming/views.py", line 49, in submit
member = Member.objects.get(email=email_address)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/manager.py", line 120, in get
return self.get_query_set().get(*args, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 300, in get
num = len(clone)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 81, in __len__
self._result_cache = list(self.iterator())
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/query.py", line 238, in iterator
for row in self.query.results_iter():
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/sql/query.py", line 287, in results_iter
for rows in self.execute_sql(MULTI):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/models/sql/query.py", line 2369, in execute_sql
cursor.execute(sql, params)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/django/db/backends/mysql/base.py", line 84, in execute
return self.cursor.execute(query, args)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg/MySQLdb/cursors.py", line 173, in execute
self.errorhandler(self, exc, value)
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/MySQL_python-1.2.3c1-py2.6-macosx-10.3-fat.egg/MySQLdb/connections.py", line 36, in defaulterrorhandler
raise errorclass, errorvalue
ProgrammingError: (1146, "Table 'test_deal.member' doesn't exist")
----------------------------------------------------------------------
Ran 1 test in 0.447s
FAILED (errors=1)
Destroying test database...
dove altro posso guardare al vedi cosa non va, perché questo tavolo non viene creato?
aggiornamento - il problema sembra essere che durante l'esecuzione dell'unità i modelli utilizzati per generare il database di test provengono dall'interno dell'applicazione anziché dall'interno del progetto. questo sembra un comportamento strano e una violazione di DRY in quanto per farlo funzionare ho bisogno di duplicare il file del modello in ogni applicazione anziché centralmente nel progetto.
qualcuno può suggerire come aggirare questo?
** Aggiornamento ** 2 - struttura di progetto si presenta così:
struttura del progetto si presenta come:
/mysite (www.whatever.com)
/application1 (facebook app, handles all urls beginning with /fb)
/application2 (www app, handles everything else in the root dir of the site)
voglio mantenere la funzionalità fb separato dal resto del sito, ma che condividono la stesso db. sto sbagliando?
Sembra che tu abbia un malinteso su dove vivono i modelli - essi * fanno * vivono nell'applicazione, non il "progetto", che è solo una raccolta di app con un file di impostazioni. Puoi pubblicare la struttura del tuo progetto? –
Avete definitivamente incollato il modello completo per noi? Non hai omesso qualcosa di simile a 'managed = True' hai? –