title: Django - Create random dummy data for testing that doesn't break the test suite
body: <p>I'm trying to think of a way to create random test data of a certain model type for running <code>python manage.py test</code>. So for example if I have a model <code>Post</code> like below.</p>
  <p><code>model.py</code></p>
  <pre><code>class Post(models.Model):
      uuid = models.UUIDField(primary_key=True)
      created = models.DateTimeField('Created at', auto_now_add=True)
      updated_at = models.DateTimeField('Last updated at', auto_now=True, blank=True, null=True)
      creator = models.ForeignKey(
          User, on_delete=models.CASCADE, related_name=&quot;post_creator&quot;)
      body = models.CharField(max_length=POST_MAX_LEN, validators=[MinLengthValidator(POST_MIN_LEN)])
  </code></pre>
  <p>some sort of library that'll generate this with random <code>body</code>, random <code>creator</code> from user table would be nice. I tried <a href="https://factoryboy.readthedocs.io/en/stable/orms.html" rel="nofollow noreferrer">factory boy</a>, but when the test DB rolls back the DB after a test function it seems to rollback factory boy created dummy data as well even if it's declared in <code>setUpTestData</code> function. This rollback process causes a constraint error since the original data no longer exists. <strong>What's a good library or way to create dummy data for Django testing that doesn't break the test suite?</strong></p>
  <p><code>dummy_factory.py</code></p>
  <pre><code>from factory.django import DjangoModelFactory
  
  class PostFactory(DjangoModelFactory):
      class Meta:
          model = Post
  
      creator = factory.Iterator(User.objects.all())
      body = factory.Faker('text')
  </code></pre>
  <p><strong>Note:</strong><br />
  Another option is to just create a function let's say <code>make_dummy_post</code> that uses <code>Post.objects.create()</code> and randomly samples a <code>User</code> and uses factory boy generators to generate <code>body</code>, but I feel like there's a better way to do it than this.</p>