Note that there are some explanatory texts on larger screens.

plurals
  1. PORunning tests with unmanaged tables in django
    primarykey
    data
    text
    <p>My django app works with tables that are not managed and have the following defined in my model like so:</p> <pre><code>class Meta: managed = False db_table = 'mytable' </code></pre> <p>When I run a simple test that imports the person, I get the following:</p> <pre><code>(person)bob@sh ~/person/dapi $ &gt; python manage.py test Creating test database for alias 'default'... DatabaseError: (1060, "Duplicate column name 'db_Om_no'") </code></pre> <p>The tests.py is pretty simple like so:</p> <pre><code>import person.management.commands.dorecall from person.models import Person from django.test import TestCase import pdb class EmailSendTests(TestCase): def test_send_email(self): person = Person.objects.all()[0] Command.send_email() </code></pre> <p>I did read in <a href="https://docs.djangoproject.com/en/dev/ref/models/options/" rel="nofollow noreferrer">django docs</a> where it says "For tests involving models with managed=False, it’s up to you to ensure the correct tables are created as part of the test setup.". So I understand that my problem is that I did not create the appropriate tables. So am I supposed to create a copy of the tables in the <code>test_person</code> db that the test framework created?</p> <p>Everytime I run the tests, the <code>test_person</code> db gets destroyed (I think) and re-setup, so how am I supposed to create a copy of the tables in <code>test_person</code>. Am I thinking about this right?</p> <p><strong>Update:</strong></p> <p>I saw <a href="https://stackoverflow.com/questions/5161173/django-tests-complain-of-missing-tables">this question on SO</a> and added the <code>ManagedModelTestRunner()</code> in <code>utils.py</code>. Though <code>ManagedModelTestRunner()</code> does get run (confirmed through inserting <code>pbd.set_trace()</code>), I still get the <code>Duplicate column name</code> error. I do not get errors when I do <code>python manage.py syncdb</code> (though this may not mean much since the tables are already created - will try removing the table and rerunning syncdb to see if I can get any clues).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload