framework icon indicating copy to clipboard operation
framework copied to clipboard

Django like migrations?

Open pariz opened this issue 11 years ago • 10 comments

As much as i love the workflow in Laravel, i feel that the whole schema/migrations part is a bit quirky.

My proposal is to look into either South for Django 1.6- or the migrations in Django 1.7.

Instead of creating schemas, you add/remove/change properties to the model directly and then sync the changes using a cli command. Pretty neat imo.

pariz avatar Jan 06 '15 13:01 pariz

You define your model attributes in Django models so django can map them to the correct SQL schema. In Eloquent , Model attributes are not declared explicitly.

reshadman avatar Jan 06 '15 14:01 reshadman

That's entirely true and something i'm fully aware of :) I've built a couple of projects using Eloquent, but this is also why i'm raising the question.

Why is it bad to declare the attributes in the model and then syncing the changes to a migration file?

pariz avatar Jan 06 '15 15:01 pariz

It is kind of and opinion-based problem. Also I thinks Eloquent is no designed to be treated like this.

reshadman avatar Jan 06 '15 16:01 reshadman

@pariz Have you tried Doctrine?

ibrasho avatar Jan 06 '15 16:01 ibrasho

Agreed, Eloquent isn't designed for this. But it abstracts away the direct need for schemas. One less file to manage per model.

It has clear gains in terms of ease of development too. Instead of referring to the schema files or the database when needing to see the properties of a model, you just open the model file and there you have it.

pariz avatar Jan 06 '15 16:01 pariz

@ibrasho doctrine 1 a bunch of years ago, haven't even given it a thought that doctrine 2 may deliver such functionality. I'll look into it :) Thanks man

pariz avatar Jan 06 '15 16:01 pariz

Missing Django.

sunzhongwei avatar May 19 '16 13:05 sunzhongwei

maybe move this over to internals because I think it warrants some discussion. i fully agree migrations are great, but there may be room for improvement.

browner12 avatar May 19 '16 14:05 browner12

I think adding this would really be a nice feature. Not just in terms of migrations but also so we can easily access schema for nice admin/api features (at least for prototyping) like auto form creation, and auto api creation (see Django REST Framework).

sgelbart avatar Dec 30 '16 16:12 sgelbart

Having attributes declared in model will be a good thing while using noSQL DBs as well because this is no more just SQL based world. Also in case of noSQL you have to defined attributes in model to avoid no set variable error. Also having django like make migrations makes it more declared than telling each and every thing to do in migrations everytime you change a small thing.

Haafiz avatar Aug 25 '18 20:08 Haafiz