esdairi's avatar

Leaving the fields created_at and updated_at empty in a database table?

Hi, I am creating some database migrations for cities and states in Laravel, they both have the created_at, and the updated_at fields, now I am trying to fill in those using an SQL script that I have found online, this is the way I will be able to do it , so My Question: is it OK if I leave them empty, and whether in any case I will have some issues if I leave them empty now, my web application is expected to scale in the future.

0 likes
5 replies
simondavies's avatar

you don't need them, they are there for you use, so you can add to your model class public $timestamps = false;, or but if your using a model etc these normally fill in automatically anyways, so you dont need to try or add then in your entry code.

lindstrom's avatar
Level 15

For tables that don't need timestamps, don't add $table->timestamps(); to your migration. If you don't add them, you must do as @simondavies says and add public $timestamps = false; to the model. If you don't use Eloquent at all and don't define a model, just don't add the timestamps. Finally, don't just copy/paste SQL you find on the internet to make your app work. Eloquent is a wonderful thing, watch the casts here and learn how to use it. IMHO, copy/paste doesn't scale--knowledge does.

1 like
esdairi's avatar

thank you @lindstrom , I just copied the list of cities, countries and states, the actual names for the whole world, I don't think this will be bad for my app, because the code is just INSERT INTO blabal blabl VALUES blabla, ti does not contain actually any logic or relationships, those I did myself using Eloquent, I thik this is OK, but I still a beginner with Laravel so if there is any thing wrong with it please tell me about .

Please or to participate in this conversation.