@@ -329,13 +329,13 @@ <h3 id="為什麼需要關聯?">1 為什麼需要關聯?</h3><p>為什麼 Mo
329
329
def change
330
330
create_table :customers do |t|
331
331
t.string :name
332
- t.timestamps
332
+ t.timestamps null: false
333
333
end
334
334
335
335
create_table :orders do |t|
336
336
t.belongs_to :customer, index: true
337
337
t.datetime :order_date
338
- t.timestamps
338
+ t.timestamps null: false
339
339
end
340
340
end
341
341
end
@@ -356,13 +356,13 @@ <h4 id="has-one-關聯">2.2 <code>has_one</code> 關聯</h4><p><code>has_one</co
356
356
def change
357
357
create_table :suppliers do |t|
358
358
t.string :name
359
- t.timestamps
359
+ t.timestamps null: false
360
360
end
361
361
362
362
create_table :accounts do |t|
363
363
t.belongs_to :supplier, index: true
364
364
t.string :account_number
365
- t.timestamps
365
+ t.timestamps null: false
366
366
end
367
367
end
368
368
end
@@ -383,13 +383,13 @@ <h4 id="has-many-關聯">2.3 <code>has_many</code> 關聯</h4><p><code>has_many<
383
383
def change
384
384
create_table :customers do |t|
385
385
t.string :name
386
- t.timestamps
386
+ t.timestamps null: false
387
387
end
388
388
389
389
create_table :orders do |t|
390
390
t.belongs_to :customer, index: true
391
391
t.datetime :order_date
392
- t.timestamps
392
+ t.timestamps null: false
393
393
end
394
394
end
395
395
end
@@ -421,19 +421,19 @@ <h4 id="has-many-through-關聯">2.4 <code>has_many :through</code> 關聯</h4><
421
421
def change
422
422
create_table :physicians do |t|
423
423
t.string :name
424
- t.timestamps
424
+ t.timestamps null: false
425
425
end
426
426
427
427
create_table :patients do |t|
428
428
t.string :name
429
- t.timestamps
429
+ t.timestamps null: false
430
430
end
431
431
432
432
create_table :appointments do |t|
433
433
t.belongs_to :physician, index: true
434
434
t.belongs_to :patient, index: true
435
435
t.datetime :appointment_date
436
- t.timestamps
436
+ t.timestamps null: false
437
437
end
438
438
end
439
439
end
@@ -494,19 +494,19 @@ <h4 id="has-one-through-關聯">2.5 <code>has_one :through</code> 關聯</h4><p>
494
494
def change
495
495
create_table :suppliers do |t|
496
496
t.string :name
497
- t.timestamps
497
+ t.timestamps null: false
498
498
end
499
499
500
500
create_table :accounts do |t|
501
501
t.belongs_to :supplier, index: true
502
502
t.string :account_number
503
- t.timestamps
503
+ t.timestamps null: false
504
504
end
505
505
506
506
create_table :account_histories do |t|
507
507
t.belongs_to :account, index: true
508
508
t.integer :credit_rating
509
- t.timestamps
509
+ t.timestamps null: false
510
510
end
511
511
end
512
512
end
@@ -531,12 +531,12 @@ <h4 id="has-and-belongs-to-many-關聯">2.6 <code>has_and_belongs_to_many</code>
531
531
def change
532
532
create_table :assemblies do |t|
533
533
t.string :name
534
- t.timestamps
534
+ t.timestamps null: false
535
535
end
536
536
537
537
create_table :parts do |t|
538
538
t.string :part_number
539
- t.timestamps
539
+ t.timestamps null: false
540
540
end
541
541
542
542
create_table :assemblies_parts, id: false do |t|
@@ -565,13 +565,13 @@ <h4 id="belongs-to-與-has-one-的應用場景">2.7 <code>belongs_to</code> 與
565
565
def change
566
566
create_table :suppliers do |t|
567
567
t.string :name
568
- t.timestamps
568
+ t.timestamps null: false
569
569
end
570
570
571
571
create_table :accounts do |t|
572
572
t.integer :supplier_id
573
573
t.string :account_number
574
- t.timestamps
574
+ t.timestamps null: false
575
575
end
576
576
577
577
add_index :accounts, :supplier_id
@@ -635,7 +635,7 @@ <h4 id="belongs-to-與-has-one-的應用場景">2.7 <code>belongs_to</code> 與
635
635
t.string :name
636
636
t.integer :imageable_id
637
637
t.string :imageable_type
638
- t.timestamps
638
+ t.timestamps null: false
639
639
end
640
640
641
641
add_index :pictures, :imageable_id
@@ -651,7 +651,7 @@ <h4 id="belongs-to-與-has-one-的應用場景">2.7 <code>belongs_to</code> 與
651
651
create_table :pictures do |t|
652
652
t.string :name
653
653
t.references :imageable, polymorphic: true, index: true
654
- t.timestamps
654
+ t.timestamps null: false
655
655
end
656
656
end
657
657
end
@@ -675,7 +675,7 @@ <h4 id="belongs-to-與-has-one-的應用場景">2.7 <code>belongs_to</code> 與
675
675
def change
676
676
create_table :employees do |t|
677
677
t.references :manager
678
- t.timestamps
678
+ t.timestamps null: false
679
679
end
680
680
end
681
681
end
0 commit comments