0
0

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 1 year has passed since last update.

Djangoスタートアップ(エラー編)※随時追記

Last updated at Posted at 2023-02-26

新しいモデルを追加すると以下の警告が表示されて、モデルの追加ができない(2023/02/28)

コマンドライン
It is impossible to add a non-nullable field 'text' to sentencedb without specifying a default. 
This is because the database needs something to populate existing rows.

説明

既存のレコードにはNULL禁止であるにも関わらず、NULLが入ってしまう。

そこで既存のレコードはどうするかを聞かれる

コマンドライン
1) Provide a one-off default now (will be set on all existing rows with a null value for this column)
2) Quit, and let me add a default in models.py

2回目以降のpython mange.py makemigrationsで発生する可能性あり

解決策

models.pyで定義したフィールドにdefault値を指定する

参考記事
https://noauto-nolife.com/post/django-non-nullable/

Template{{% url 'portfolio_app:worksTemplate pk=work.pk %'}}と記述したら、NoReverseMatch at/エラーが表示される(2023/04/15)

解決策

×{{% url 'portfolio_app:worksTemplate pk=work.pk %'}}
{{% url 'portfolio_app:worksTemplate' pk=work.pk %}}
pk=までシングルクォーテーションでくくる必要がなかった。

views.pypkを認識できない

解決策1

(関数ベースビューの場合)引数にpkを追加する

views.py
#def worksTemplate(request):
def worksTemplate(request, pk):#引数にpkを追加
    works = get_object_or_404(Post, pk=pk)
    return render(request, 'portfolio_app/worksTemplate.html', {'works' : works})

0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?