【问题标题】:Django depracation error when calling 'syncdb'调用'syncdb'时出现Django depracation错误
【发布时间】:2013-04-06 06:41:47
【问题描述】:

我正在开发我的第一个 Django 应用程序,但遇到了一个奇怪的错误。我查看了looked it up 并检查了我正在使用的 Django 文档中的 1.5.1 版本,它没有说明这个错误。

pat.py:9: DeprecationWarning: django.utils.hashcompat is deprecated; use hashlib instead
DeprecationWarning)

TypeError: __init__() got an unexpected keyword argument 'verify_exists'

我正在使用安装了 Django 的虚拟环境(pip freeze 输出):

Django==1.5.1
argparse==1.2.1
django-db-log==2.2.1
psycopg2==2.4.6
wsgiref==0.1.2
yolk==0.4.3

另外,重要的是要注意,当我停用我的虚拟环境时,我尝试运行 python manage.py syncdb - 没有错误。此错误仅在我使用虚拟环境时发生。有任何想法吗?在此先感谢,如果这是一个小问题,我很抱歉,我对 Django 很陌生!

编辑:我发现 this 看起来很有希望,但通过我唯一的模型,我从不使用 URLField()...

EDIT2:我拥有的唯一 models.py:

from django.db import models


class Category(models.Model):
    name = models.CharField(max_length=50)
    slug = models.SlugField(max_length=50, unique=True, help_text='Unique value for product page URL, created from name.')
    description = models.TextField()
    is_active = models.BooleanField(default=True) 
    meta_keywords = models.CharField("Meta Keywords", max_length=255, help_text='Comma-delimited set of SEO keywords for meta tag')
    meta_description = models.CharField("Meta description", max_length=255, help_text='Content for description meta tag')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        db_table = 'categories'
        ordering = ['-created_at']
        verbose_name_plural = 'Categories'

    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return ('catalog_category', (), {'category_slug': self.slug})

class Product(models.Model):
    name = models.CharField(max_length=255, unique=True)
    slug = models.SlugField(max_length=255, unique=True, help_text= 'Unique value for product page URL, create from name.')
    brand = models.CharField(max_length=50)
    sku = models.CharField(max_length=50)
    price = models.DecimalField(max_digits=9, decimal_places=2)
    old_price = models.DecimalField(max_digits=9, decimal_places=2, blank=True, default=0.00)
    image = models.CharField(max_length=50)
    is_active = models.BooleanField(default=True)
    is_bestseller = models.BooleanField(default=False)
    is_featured = models.BooleanField(default=False)
    quantity = models.IntegerField()
    description = models.TextField()
    meta_keywords = models.CharField(max_length=255, help_text='Comma-delimited set of SEO keywords for meta tag')
    meta_description = models.CharField(max_length=255, help_text='Content for description meta tag')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    categories = models.ManyToManyField(Category)

    class Meta:
        db_table = 'products'
        ordering = ['-created_at']

    def __unicode__(self):
        return self.name

    @models.permalink
    def get_absolute_url(self):
        return('catalog_product', (), {'product_slug': self.slug})

    def sale_price(self):
        if (self.old_price > self.price):
            return self.price
        else: 
            return None

【问题讨论】:

  • 您将 verify_exists 参数传递给不接受它的类构造函数。你能包括你项目的一些源代码吗? pat.py 第 9 行附近的代码是什么?
  • 安装的第三方应用怎么样,你升级到最新版本了吗?
  • 凯瑟琳提出了一个很好的观点。我猜想 django-db-log 是罪魁祸首,因为它看起来 3 年内没有更新过。

标签: python django virtualenv


【解决方案1】:

我想我找到了原因,查看了您项目中安装的应用程序。我发现django-db-log 使用models.URLField(verify_exists=False, null=True, blank=True),在新版本中已弃用。

他们的项目还没有升级,所以也许你可以在他们的项目中拉一个请求或卸载那个应用程序

更新:来自@NathanVillaescusa

 from django.utils.hashcompat import md5_constructor //deprecated also

【讨论】:

  • 目前,他们有问题需要解决,所以如果您要求升级版本,他们无法立即完成。
  • django-db-log 也是弃用警告的原因:github.com/dcramer/django-db-log/blob/master/djangodblog/…
  • @NathanVillaescusa 是的,这是第一个错误。下一个错误是关于 verify_exist。更好的方法是卸载该应用并替换它
  • 谢谢!我原本以为 djangodblog 是最新的(这是因为当我更新它时,没有找到更新)。距离上次提交 3 年才有意义。
猜你喜欢
  • 2014-09-07
  • 2012-10-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-02-20
  • 2014-09-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多