I was trying to add data dynamically from admin to my HTML page in django but when I try to add data in admin panel it is not showing anything in the HTML file. when I do makemigrations
i am getting this below
You are trying to add a non-nullable field 'link' to researchpaper without a default; we can't do that (the database needs something to populate existing rows).
Please select a fix:
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
Select an option:
In admin panel I am getting this error
models.py
from django.db import models
class researchpaper(models.Model):
title = models.CharField(max_length=300)
publication = models.CharField(max_length=200)
link = models.CharField(max_length=300)
authors = models.CharField(max_length=200)
year = models.DateField("date published")
views.py
def publications(request):
data = researchpaper.objects.all()
return render(request, 'lab/publications.html',context={
"datas": data
})
urls.py
path('publications', views.publications, name='publications'),
HTML file
{% for public in datas %}
<tr>
<td>
<h5>2021</h5>
<p style="color: black;"><b>{{public.title}}</b></p>
<p style="font-size: 14px;"><i>{{public.publications}}</i></p>
<p style="font-size: 14px;"><i>{{public.author}}</i></p>
</td>
<td><a href="#"
target="blank" style="color: dodgerblue;"><i class="ai ai-google-scholar-square ai-2x"
style="padding-right: 10px;"></i></a></td>
</tr>
<tr>
<td>
<hr>
</td>
</tr>
{% endfor %}
why I am getting this problem please help
CodePudding user response:
Choose the first option and it will appear again, Choose it again and add dummy data like "R", if this doesn't work try to delete all migration file except __init__
file as well remove db.sqlite3
file if you use SQLite.