M
M
maestro072017-04-11 15:13:09
Django
maestro07, 2017-04-11 15:13:09

How to make a migration in django?

Created a class in models.py

class Post(models.Model):
    title = models.CharField(max_length=200)
    pdf = models.FileField()
    time = models.DateTimeField(auto_now_add = True)


    def __unicode__(self):
        return self.title

    def __str__(self):
        return self.title

    def get_absolute_url(self):
        return reverse("posts:detail", kwargs={"id": self.id})

    class Meta:
        ordering = ['-time']

typed the migration commands but it is not in the admin part

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
AlexandrBirukov, 2017-04-11
@AlexandrBirukov

you need to run ./manage.py makemigrations, and then ./manage.py migrate from the directory where the manage.py file is located, and accordingly, you first need to start the virtual environment, if it was supposed to work from under it, and you also need to add to admin.py models, like from .models import Post and admin.site.register(Post)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question