Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.



Published on

PyCon mini KUMAMOTO 2017での発表

Published in: Software
  • Be the first to comment

  • Be the first to like this


  1. 1. from django.db import models class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30)
  2. 2. CREATE TABLE myapp_person ( "id" serial NOT NULL PRIMARY KEY, "first_name" varchar(30) NOT NULL, "last_name" varchar(30) NOT NULL );
  3. 3. class Migration(migrations.Migration): initial = True dependencies = [ ] operations = [ migrations.CreateModel( name='SampleModel1', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('name', models.CharField(max_length=200)), ], ), ]
  4. 4. $ ./ sqlmigrate app1 0001 BEGIN; -- -- Create model SampleModel1 -- CREATE TABLE `app1_samplemodel1` (`id` integer AUTO_INCREMENT NOT NULL PRIMARY KEY, `name` varchar(200) NOT NULL); COMMIT;
  5. 5. $ ./ migrate Operations to perform: Apply all migrations: admin, app1, auth, contenttypes, sessions Running migrations: Applying app1.0001_initial... OK
  6. 6. id app name applied 12 auth 0008_alter_user_usernam e_max_length 2017-03-31 05:02:26.307972 13 sessions 0001_initial 2017-03-31 05:02:26.361356 14 app1 0001_initial 2017-03-31 05:29:31.189362
  7. 7. $ python reset_db You have requested a database reset. This will IRREVERSIBLY DESTROY ALL data in the database "migrations_demo". Are you sure you want to do this? Type 'yes' to continue, or 'no' to cancel: yes Reset successful.
  8. 8. $ python showmigrations admin [X] 0001_initial [X] 0002_logentry_remove_auto_add app1 [X] 0001_initial auth [X] 0001_initial [X] 0002_alter_permission_name_max_length [X] 0003_alter_user_email_max_length [X] 0004_alter_user_username_opts [X] 0005_alter_user_last_login_null [X] 0006_require_contenttypes_0002 [X] 0007_alter_validators_add_error_messages [X] 0008_alter_user_username_max_length contenttypes [X] 0001_initial [X] 0002_remove_content_type_name sessions [X] 0001_initial