migrations: admin, auth, contenttypes, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying sessions.0001_initial... OK @KatiaNakamura
Create model Advertiser (.env) Katias-MacBook-Pro:pythonbrazil katia$ ./manage.py makemigrations Migrations for 'core': core/migrations/0002_apartment_house.py - Create model Apartment - Create model House (.env) Katias-MacBook-Pro:pythonbrazil katia$ ./manage.py makemigrations Migrations for 'core': core/migrations/0003_ad.py - Create model Ad @KatiaNakamura
Create model Ad -- CREATE TABLE "core_ad" ("id" integer NOT NULL PRIMARY KEY AUTOINCREMENT, "status" integer NOT NULL, "published_date" datetime NULL, "object_id" integer unsigned NOT NULL, "ctype_id" integer NOT NULL REFERENCES "django_content_type" ("id"), "owner_id" integer NOT NULL REFERENCES "core_advertiser" ("user_ptr_id")); CREATE INDEX "core_ad_ctype_id_f90eab81" ON "core_ad" ("ctype_id"); CREATE INDEX "core_ad_owner_id_0bb18e6e" ON "core_ad" ("owner_id"); COMMIT; @KatiaNakamura
all migrations: core Running migrations: Applying core.0001_initial... OK Applying core.0002_apartment_house... OK Applying core.0003_ad... OK (.env) Katias-MacBook-Pro:pythonbrazil katia$ ./manage.py migrate core 0002 Operations to perform: Target specific migration: 0002_apartment_house, from core Running migrations: Rendering model states... DONE Unapplying core.0003_ad... OK @KatiaNakamura
= models.TextField(null=True, blank=True) state = models.CharField(max_length=255) # city = models.CharField(max_length=255) country = models.CharField(max_length=255) class Meta: abstract = True (.env) Katias-MacBook-Pro:pythonbrazil katia$ ./manage.py makemigrations Did you rename apartment.city to apartment.state (a CharField)? [y/N] y Did you rename house.city to house.state (a CharField)? [y/N] y Migrations for 'core': core/migrations/0004_auto_20171006_2348.py - Rename field city on apartment to state - Rename field city on house to state @KatiaNakamura Renomear o campo city para state
= models.TextField(null=True, blank=True) state = models.CharField(max_length=255) country = models.CharField(max_length=255) class Meta: abstract = True class House(Property): pass class Apartment(Property): floor = models.PositiveIntegerField() @KatiaNakamura
= models.TextField(null=True, blank=True) state = models.CharField(max_length=255) country = models.CharField(max_length=255) class Meta: abstract = True class House(Property): pass class Apartment(House): floor = models.PositiveIntegerField() @KatiaNakamura O que queremos:
Did you rename the core.Apartment model to ApartmentOld? [y/N] y Migrations for 'core': core/migrations/0005_auto_20171007_0010.py - Rename model Apartment to ApartmentOld @KatiaNakamura 1º passo: Renomear a tabela Apartment para ApartmentOld
'core': core/migrations/0007_auto_20171007_0026.py @KatiaNakamura 3º passo: Criar uma migração vazia e copiar os dados de ApartmentOld para a nova tabela Apartment
= models.TextField(null=True, blank=True) state = models.CharField(max_length=255) country = models.CharField(max_length=255) class Apartment(House): floor = models.PositiveIntegerField() (.env) Katias-MacBook-Pro:pythonbrazil katia$ python manage.py makemigrations Migrations for 'core': core/migrations/0008_delete_apartmentold.py - Delete model ApartmentOld @KatiaNakamura 4º passo: Remover a nova tabela ApartmentOld e remover a classe abstrata Property
following migrations: - 0001_initial - 0002_apartment_house - 0003_ad - 0004_auto_20171006_2348 - 0005_auto_20171007_0010 - 0006_apartment Do you wish to proceed? [yN] y Optimizing... Optimized from 8 operations to 5 operations. Created new squashed migration /Users/katia/Projects/pythonbrazil/core/migrations/0001_squashed_0006_apartment.py You should commit this migration but leave the old ones in place; the new migration will be used for new installs. Once you are sure all instances of the codebase have applied the migrations you squashed, you can delete them. @KatiaNakamura
migrations: admin, auth, contenttypes, core, sessions Running migrations: Applying contenttypes.0001_initial... OK Applying auth.0001_initial... OK Applying admin.0001_initial... OK Applying admin.0002_logentry_remove_auto_add... OK Applying contenttypes.0002_remove_content_type_name... OK Applying auth.0002_alter_permission_name_max_length... OK Applying auth.0003_alter_user_email_max_length... OK Applying auth.0004_alter_user_username_opts... OK Applying auth.0005_alter_user_last_login_null... OK Applying auth.0006_require_contenttypes_0002... OK Applying auth.0007_alter_validators_add_error_messages... OK Applying auth.0008_alter_user_username_max_length... OK Applying core.0001_squashed_0006_apartment... OK Applying core.0007_auto_20171007_0026... OK Applying core.0008_delete_apartmentold... OK Applying sessions.0001_initial... OK @KatiaNakamura Mirgração em um novo banco de dados: