2016-01-03 3 views
0

Я внес изменения в моей модели и пытался перенести базу данных с помощью:База данных postgresql ResetDjango? флеш не работает

python3 manage.py makemigrations 
python3 manage.py migrate 

я получил следующий вывод:

[email protected]:/vagrant/grader$ python3 manage.py makemigrations 
No changes detected 
[email protected]:/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' 

Я не знаю, почему миграция Безразлично Не работай. Я вижу, что причиной является некоторая ошибка типа, но не знаю, в чем причина.

Я решил, что попытаюсь просто полностью очистить базу данных, так как у меня нет соответствующих данных. Я планировал использовать:

python3 manage.py flush 
python3 manage.py makemigrations 
python3 manage.py migrate 

Но получил следующий вывод:

[email protected]:/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. 

Как можно полностью сбросить базу данных Psql Django?

+0

Я думаю, у меня была аналогичная проблема. Если вам не нужны данные в БД, просто выберите решение из моего вопроса http://stackoverflow.com/questions/33521402/django-validationerror-date-format-exception/33521712?noredirect=1#comment54824928_33521712 –

+1

Спасибо! Он работал, чтобы сначала удалить файлы миграции, а затем запустить миграцию agian – user1283776

+0

рад помочь вам! :) –

ответ

0

Как говорится в сообщении, запустите python3 manage.py sqlflush, чтобы увидеть, какие команды SQL пытается запустить Django.

Убедитесь, что все таблицы, используемые в команде, существуют в базе данных.

 Смежные вопросы

  • Нет связанных вопросов^_^