在网站上进行更改的问题,托管在 pythonanywhere 上

Issue in making changes on the site, hosted on pythonanywhere

我在 pythonanywhere 上托管我的 blog site。我在数据库中还有一个订阅者模型字段。问题是每当我在本地创建一个新的 post 并将其拉入 pythonanywhere bash 控制台时。本地数据库替换生产数据库。这导致丢失用户提供的所有数据。如何阻止某些字段在每次拉取请求时更改?

class Category(models.Model):
    created_on = models.DateTimeField(auto_now_add=True, verbose_name="Created on")
    updated_on = models.DateTimeField(auto_now=True, verbose_name="Updated on")
    title = models.CharField(max_length=255, verbose_name="Title")

    class Meta:
        verbose_name = "Category"
        verbose_name_plural = "Categories"
        ordering = ['title']

    def __str__(self):
        return self.title

class Post(models.Model):
    author = models.ForeignKey('auth.User', on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    text = models.TextField()
    image_file = models.ImageField(upload_to='media', null=True, blank=True)
    image_url = models.URLField(null=True)
    category = models.ForeignKey(Category, verbose_name="Category", on_delete=models.CASCADE, null=True)
    published_date = models.DateTimeField(blank=True, default=timezone.now ,null=True)

    class Meta:
        verbose_name = "Post"
        verbose_name_plural = "Posts"
        ordering = ('-published_date',)

    def get_absolute_url(self):
        return reverse("post_detail",kwargs={'pk':self.pk})

    def __str__(self):
        return self.title


class Comment(models.Model):
    post = models.ForeignKey(Post,on_delete=models.CASCADE,related_name='comments')
    name = models.CharField(max_length=80)
    body = models.TextField()
    created_on = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-created_on',)

    def __str__(self):
        return 'Comment {} by {}'.format(self.body, self.name)


class Subscribe(models.Model):
    email = models.EmailField()
    subscribed_on = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ('-subscribed_on',)

    def __str__(self):
        return 'Subscribed by {} on {}'.format(self.email, self.subscribed_on)

听起来您正在使用 sqlite,并且您已将数据库文件包含在 git 中。这意味着每次您提交(无论是在 PythonAnywhere 上还是在本地)时,您都在用您提交的数据库替换您的数据库。您可以通过将其文件名添加到 .gitignore 文件并将其从存储库中删除(使用 git rm --staged)从存储库中排除您的数据库。