0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

DjangoでModelの変更

Last updated at Posted at 2020-03-03

データベースの定義を間違えたので
Models.py内のDateFieldをDurationFieldへ変えたところ、エラーが発生した。
そこで一からデータベースを作り直す方法をとった。
注.作成したUserや他のテーブルも消えるため要注意
注2.Django上でデータベースを変更する方法が絶対にあるはずなのでできればそちらを使う

やったこと

  1. migrationファイルの全消去
  2. データベースの削除

migrationファイルの削除

ファイル構造は以下とします。

$ls
 -project -app -migrations
               Lviews.pyなど
          Lmanage.py
          Lconfig - settings.pyなど
$cd [appへのパス]
$rm -d -r migrations/

データベースの削除

sqliteの場合はsqliteファイルを削除
僕はPostgreSQLを使っていたので、PdAdmin4から直接データベースを削除して、同じ名前のデータベースを再度作りました。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?