// roll back
php artisan migrate:rollback
php artisan migrate:rollback --step=5 // rollback the last five migrations
php artisan migrate:reset // roll back all of your application's migrations
roll back all of your migrations and then execute the migrate command. This command effectively re-creates your entire database:
php artisan migrate:refresh
php artisan migrate:refresh --step=5
//drop all tables and re-run all migrations
php artisan migrate:fresh
2019年5月20日月曜日
laravel table schema mapping
Auto-incrementing UNSIGNED BIGINT (primary key) => $table->bigIncrements('id');
DATE => $table->date('created_at');
DATETIME => $table->dateTime('created_at');
VARCHAR => $table->string('name', 100);
TEXT => $table->text('description');
TIMESTAMP => $table->timestamp('added_on');
Allows (by default) NULL values to be inserted into the column
->nullable($value = true)
Specify a "default" value for the column
->default($value)
Add a comment
->comment('my comment')
Set INTEGER columns as auto-increment (primary key)
->autoIncrement()
DATE => $table->date('created_at');
DATETIME => $table->dateTime('created_at');
VARCHAR => $table->string('name', 100);
TEXT => $table->text('description');
TIMESTAMP => $table->timestamp('added_on');
Allows (by default) NULL values to be inserted into the column
->nullable($value = true)
Specify a "default" value for the column
->default($value)
Add a comment
->comment('my comment')
Set INTEGER columns as auto-increment (primary key)
->autoIncrement()
2017年11月30日木曜日
DjangoのModel使用
1)Modelを定義
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
appフォルダーにmodels.pyにTableとColumnを定義
from django.db import models
# Create your models here.
class Question(models.Model):
question_text = models.CharField(max_length=200)
pub_date = models.DateTimeField('date published')
class Choice(models.Model):
question = models.ForeignKey(Question, on_delete=models.CASCADE)
choice_text = models.CharField(max_length=200)
votes = models.IntegerField(default=0)
2)appをProjectに結び付く
settings.pyのINSTALLED_APPSにappを追加
INSTALLED_APPS = [
'polls.apps.PollsConfig',
.....
3)migrations作成
python manage.py makemigrations polls
4)migrate実施
python manage.py sqlmigrate polls 0001 #どんなSQL実行されるか確認
python manage.py migrate
登録:
投稿 (Atom)