首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ResetDjango postgresql数据库?刷新不起作用

ResetDjango postgresql数据库?刷新不起作用
EN

Stack Overflow用户
提问于 2016-01-03 18:24:30
回答 1查看 1.1K关注 0票数 0

我已经对我的模型进行了更改,并尝试使用以下命令迁移数据库:

代码语言:javascript
运行
复制
python3 manage.py makemigrations
python3 manage.py migrate

我得到了以下输出:

代码语言:javascript
运行
复制
vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py makemigrations
No changes detected
vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py migrate     Operations to perform:
  Apply all migrations: contenttypes, sessions, admin, auth, core
Running migrations:
  Rendering model states... DONE
  Applying core.0002_auto_20160103_0955...Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 350, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/__init__.py", line 342, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.4/dist-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/local/lib/python3.4/dist-packages/django/db/migrations/operations/fields.py", line 62, in database_forwards
    field,
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 382, in add_field
    definition, params = self.column_sql(model, field, include_default=True)
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 145, in column_sql
    default_value = self.effective_default(field)
  File "/usr/local/lib/python3.4/dist-packages/django/db/backends/base/schema.py", line 210, in effective_default
    default = field.get_db_prep_save(default, self.connection)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/related.py", line 910, in get_db_prep_save
    return self.target_field.get_db_prep_save(value, connection=connection)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/__init__.py", line 728, in get_db_prep_save
    prepared=False)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/__init__.py", line 968, in get_db_prep_value
    value = self.get_prep_value(value)
  File "/usr/local/lib/python3.4/dist-packages/django/db/models/fields/__init__.py", line 976, in get_prep_value
    return int(value)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'datetime.datetime'

我不知道为什么迁移不起作用。我可以看到原因是某种类型的错误,但不知道是什么原因。

我想我会尝试完全清除数据库,因为我没有相关的数据。我计划使用:

代码语言:javascript
运行
复制
python3 manage.py flush  
python3 manage.py makemigrations
python3 manage.py migrate

但得到了以下输出:

代码语言:javascript
运行
复制
vagrant@vagrant-ubuntu-trusty-64:/vagrant/grader$ python3 manage.py flush
You have requested a flush of the database.
This will IRREVERSIBLY DESTROY all data currently in the 'graderdb' database,
and return each table to an empty state.
Are you sure you want to do this?

    Type 'yes' to continue, or 'no' to cancel: yes
CommandError: Database graderdb couldn't be flushed. Possible reasons:
  * The database isn't running or isn't configured correctly.
  * At least one of the expected database tables doesn't exist.
  * The SQL was invalid.
Hint: Look at the output of 'django-admin sqlflush'. That's the SQL this command wasn't able to run.
The full error: cannot truncate a table referenced in a foreign key constraint
DETAIL:  Table "core_mark" references "core_student".
HINT:  Truncate table "core_mark" at the same time, or use TRUNCATE ... CASCADE.

如何完全重置Django psql数据库?

EN

回答 1

Stack Overflow用户

发布于 2016-01-03 18:32:11

正如消息所说,请运行python3 manage.py sqlflush查看Django试图运行的SQL命令。

检查命令中使用的所有表是否都存在于数据库中。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34575487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档