使用django heroku对django和heroku postgress进行去加密的问题

使用django heroku对django和heroku postgress进行去加密的问题,django,heroku,Django,Heroku,因此,我有这个应用程序,我希望部署到Heroku。我使用django heroku,因此它可以自动运行我的postgres sql。 我将release:python mannge.py migrate添加到我的Procfile。 在构建之后,我得到一个部署失败的错误,即Release命令失败。打开日志时,出现以下错误: psycopg2.ProgrammingError: cannot cast type timestamp with time zone to integer LINE 1:

因此,我有这个应用程序,我希望部署到Heroku。我使用django heroku,因此它可以自动运行我的postgres sql。 我将
release:python mannge.py migrate
添加到我的
Procfile
。 在构建之后,我得到一个部署失败的错误,即
Release命令失败
。打开日志时,出现以下错误:

psycopg2.ProgrammingError: cannot cast type timestamp with time zone to integer
LINE 1: ...LUMN "established" TYPE integer USING "established"::integer
                                                          ^
我的带有
已建立
字段的模型如下所示:

from django.db import models

# Create your models here.

class FederalMinistry(models.Model):
    full_name = models.CharField(max_length=400)
    short_name = models.CharField(max_length=20)
    description = models.TextField()
    established = models.PositiveIntegerField()
    # logo = models.ImageField(upload_to='fed_min_logos', blank=True, null=True, default='N/A')
    current_minister = models.CharField(max_length=500)
    permanent_secretary = models.CharField(max_length=500, default='N\A')
    headquarters = models.CharField(max_length=100, default='Abuja')
    twitter = models.URLField(blank=True, null=True, default='N/A')
    website = models.URLField(blank=True, null=True, default='N/A')

class Meta:
    verbose_name_plural = 'Federal Ministries'

def __str__(self):
    return self.full_name
请问我为什么要得到错误和他的修复。我对博士后一无所知

以下是请求的完整回溯:

/app/.heroku/python/lib/python3.6/site-packages/psycopg2/__init__.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <http://initd.org/psycopg/docs/install.html#binary-install-from-pypi>.
  """)
Operations to perform:
  Apply all migrations: admin, airports, auth, contenttypes, federal_ministries, sessions, states, universities
Running migrations:
  Applying federal_ministries.0002_auto_20190310_0129...Traceback (most recent call last):
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: cannot cast type timestamp with time zone to integer
LINE 1: ...LUMN "established" TYPE integer USING "established"::integer
                                                          ^
The above exception was the direct  cause of the following exception:
Traceback (most recent call last):
  File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 316, in run_from_argv
self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 353, in execute
output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/base.py", line 83, in wrapped
res = handle_func(*args, **kwargs)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/core/management/commands/migrate.py", line 203, in handle
fake_initial=fake_initial,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 117, in migrate
state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 147, in _migrate_all_forwards
state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/migration.py", line 124, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/migrations/operations/fields.py", line 216, in database_forwards
schema_editor.alter_field(from_model, from_field, to_field)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 523, in alter_field
old_db_params, new_db_params, strict)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/postgresql/schema.py", line 122, in _alter_field
new_db_params, strict,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 663, in _alter_field
params,
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/base/schema.py", line 133, in execute
cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 68, in execute
return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
  File "/app/.heroku/python/lib/python3.6/site-packages/django/db/utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
 Q File "/app/.heroku/python/lib/python3.6/site-packages/django/db/backends/utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: cannot cast type timestamp with time zone to integer
LINE 1: ...LUMN "established" TYPE integer USING "established"::integer
以及依赖项
0001_首字母
文件:

from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
]

    operations = [
    migrations.CreateModel(
        name='FederalMinistry',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('full_name', models.CharField(max_length=400)),
            ('short_name', models.CharField(max_length=20)),
            ('description', models.TextField()),
            ('established', models.DateTimeField()),
            ('current_minister', models.CharField(max_length=500)),
            ('permanent_secretary', models.CharField(default='N\\A', max_length=500)),
            ('headquarters', models.CharField(default='Abuja', max_length=100)),
            ('twitter', models.URLField(blank=True, default='N/A', null=True)),
            ('website', models.URLField(blank=True, default='N/A', null=True)),
        ],
    ),
]

如果您试图在PostgreSQL中将
时间戳
强制转换为
PositiveIntegerField
,您必须知道您不能

使用
DateTimeField
代替
PositiveIntegerField
作为可设置的


我认为这是相关的,请查看更多信息。

我知道了。我只需要重置迁移并删除db.sqlite文件,然后运行迁移并再次迁移。修好了

已建立的
更改为
日期时间字段
,而不是
正整数字段
显示全部回程。您正试图在该字段中设置日期时间。我刚刚查看了初始迁移文件和002文件中的
已建立的
字段。第一个是DateTime字段,第二个是正整数。所以我认为这就是问题的根源。它是否有助于清除所有迁移并销毁所有数据库?已建立的数据库的格式仅为一年。使用datetimefield意味着我还要添加一天和一个月。此外,为什么PostgresSQL认为我在为它添加时间。我们的想法是,这些值应该像1980年或1845年。因为他“看到”您在试图插入到
PositiveIntegerField
的值中有一个时区。
from django.db import migrations, models


class Migration(migrations.Migration):

    initial = True

    dependencies = [
]

    operations = [
    migrations.CreateModel(
        name='FederalMinistry',
        fields=[
            ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
            ('full_name', models.CharField(max_length=400)),
            ('short_name', models.CharField(max_length=20)),
            ('description', models.TextField()),
            ('established', models.DateTimeField()),
            ('current_minister', models.CharField(max_length=500)),
            ('permanent_secretary', models.CharField(default='N\\A', max_length=500)),
            ('headquarters', models.CharField(default='Abuja', max_length=100)),
            ('twitter', models.URLField(blank=True, default='N/A', null=True)),
            ('website', models.URLField(blank=True, default='N/A', null=True)),
        ],
    ),
]