Skip to content

Commit ffd903b

Browse files
authored
BookInstance.book needs default value (mdn#89)
* Add default null value for BookInstance.book * Add migration for default BookInstance.book value
1 parent 02132ec commit ffd903b

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Generated by Django 3.1.2 on 2021-03-02 06:30
2+
3+
from django.db import migrations, models
4+
import django.db.models.deletion
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('catalog', '0023_auto_20201201_0238'),
11+
]
12+
13+
operations = [
14+
migrations.AlterField(
15+
model_name='bookinstance',
16+
name='book',
17+
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.RESTRICT, to='catalog.book'),
18+
),
19+
]

‎catalog/models.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class BookInstance(models.Model):
7171
"""Model representing a specific copy of a book (i.e. that can be borrowed from the library)."""
7272
id = models.UUIDField(primary_key=True, default=uuid.uuid4,
7373
help_text="Unique ID for this particular book across whole library")
74-
book = models.ForeignKey('Book', on_delete=models.RESTRICT)
74+
book = models.ForeignKey('Book', on_delete=models.RESTRICT, null=True)
7575
imprint = models.CharField(max_length=200)
7676
due_back = models.DateField(null=True, blank=True)
7777
borrower = models.ForeignKey(User, on_delete=models.SET_NULL, null=True, blank=True)

0 commit comments

Comments
 (0)