0

I would like to know is there any feature in laravel to generate migration scripts dynamically ( I mean scripts not migration files) like in Doctrine?

I have researched in the internet but didn't find a solution.

In Eloquent I generated migration files and wrote migration scripts manully. But in Doctrine I can generate migration script from entities (models) by issuing command migrations:diff, migrations:migrate etc. Thanks in advance.

Ersoy
  • 8,816
  • 6
  • 34
  • 48
Kiren S
  • 3,037
  • 7
  • 41
  • 69
  • Do you have any information on column types/lenghts/nullable/unique in your Model? – brombeer Apr 19 '20 at 10:05
  • I do not have those. But could you please let me know how can I mention those. Any reference? – Kiren S Apr 19 '20 at 10:29
  • I don't have any reference, sorry, was just wondering how you'd want to generate migrations without this data. Annotations maybe? Good luck – brombeer Apr 19 '20 at 10:33
  • yes from annotations or other configs – Kiren S Apr 19 '20 at 10:51
  • I didnt find a annotation models in Laravel yet. – Kiren S Apr 19 '20 at 10:52
  • My idea is to create models with proper annotatoions, then just run a command to generate migrations then run another command migrate to migrate it to database. Advantage is that we only need to concentrate on models without worrying database – Kiren S Apr 19 '20 at 13:03

1 Answers1

0

You never define any of your table's fields in your Model class, so Laravel doesn't even know where to get the diff in your database.

But if your database is already there, check this question: how to create migration from existing database in laravel

HosseyNJF
  • 491
  • 1
  • 6
  • 18
  • It should not be from existing tables it should be from models – Kiren S Apr 19 '20 at 10:00
  • @KirenSiva Then there's no way because Laravel doesn't know which models have which fields. In a framework like Django, It's possible because you explicitly define the fields inside the model itself. – HosseyNJF Apr 19 '20 at 10:02