× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Django tests and primary key.

Alexander Davydov
Mar 14, 2015
<p>When you run django test, it always creates a new test database to not damage production data. And it also flushes the test database after each test, rather then deletes it.</p> <p><span style="color:rgb(95, 99, 102)">Thus, for any test case we cannot assume that when we create a new object in an empty database it's primary key would have a pk = 1.</span></p> <p>Rather, we should <span style="color:rgb(95, 99, 102)">just ask for the first element: </span><code>Project.objects.all()[0]</code><span style="color:rgb(95, 99, 102)">.</span></p> <p> </p> <p> </p>
comments powered by Disqus