마이그레이션과 편집하십시오 사용하여 파일을 찾았다.
<! - 언어: php - >.
<?php
public function up()
{
Schema::create('users', function ($table) {
$table->integer("paid");
});
}
내가 터미널 설치 php 선보인 ','. '와' 마이그레이션합니다 실행하십시오 마이그레이션합니다:
Add new 열을 어떻게 합니까?
마이그레이션과 마이그레이션합니다 장인이 만드는 데 사용할 수도 있습니다. (make 명령을 cli. 특정 이름을 사용하여 충돌하는 것을 막기 위해 기존 모델
대한 라라벨 3:
php artisan migrate:make add_paid_to_users
라라벨 대한 5+:
php artisan make:migration add_paid_to_users_table --table=users
그런 다음 () '' 테이블 스키마 사용해야 하는 방법 (예, re 액세스하면 you& # 39 표, 새로 생성하는 것이 아니라 기존). 그리고 이렇게 열을 추가할 수 있습니다.
<! - 언어: php - >.
public function up()
{
Schema::table('users', function($table) {
$table->integer('paid');
});
}
public function down()
{
Schema::table('users', function($table) {
$table->dropColumn('paid');
});
}
다음 네 마이그레이션과 실행할 수 있습니다.
<! - 언어: > 내주었다.
php artisan migrate
이것은 모두 모두 잘 대한 문서에서 다루는 라라벨 3:
및 라라벨 4 / 라라벨 5:
편집:
정수 (& # 39, paid& # 39;), '$ table-> 사용하여 ->, 후 (& # 39, whichever_column& # 39,),' 후 이 필드를 추가하고 특정 얻어맞았다.
빨리 플래깅 " table" 셨으며 만들기 위해 사용할 수 있습니다. -; 다음과 같습니다.
php artisan make:migration add_paid_to_users --table="users"
그러면 '업' 와 '다운' 메서드입니다 자동으로 내용:
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
//
});
}
이와 비슷하게, '만들기 [" table_name";]' 옵션을 사용할 수 있는 새로운 마이그레이션과 만들 때 더 많은 상용 데이터베이스에구성원을 마이그레이션과 추가할 예정입니다. 하지만 그들 로드되는지 도움됐네 할 때는 작은 포인트!
마이그레이션과 이 명령을 실행하여 새로운 것을 만들 수 있습니다. 마이그레이션과 만들기
php artisan make:migration add_store_id_to_users_table --table=users
새로운 파일, 폴더 / 마이그레이션과 데이터베이스에 다음과 같은 항목을 마이그레이션과 합니다.
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AddStoreIdToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
// 1. Create new column
// You probably want to make the new column nullable
$table->integer('store_id')->unsigned()->nullable()->after('password');
// 2. Create foreign key constraints
$table->foreign('store_id')->references('id')->on('stores')->onDelete('SET NULL');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
// 1. Drop foreign key constraints
$table->dropForeign(['store_id']);
// 2. Drop the column
$table->dropColumn('store_id');
});
}
}
그 후 명령을 실행합니다.
php artisan migrate
php artisan migrate:rollback
새 열을 스키마에는 만들기 다음과 같은 초기 '내' 방법을 추가할 수 있습니다.
Schema::create('users', function($table) {
$table->integer("paied");
$table->string("title");
$table->text("description");
$table->timestamps();
});
이미 만든 경우 해당 테이블의 테이블 추가할 수 있습니다 '새' 테이블 스키마 마이그레이션과 열을 만들어 사용하는 방법:
Schema::table('users', function($table) {
$table->string("title");
$table->text("description");
$table->timestamps();
});
이 문서는 이에 대한 철저한 상당히 hasn& # 39 에서, 별로 변화가 너무 [버전 3] [1] 에서 [버전 4] [2].
[1]: http://laravel.com/docs/database/schema # 열 추가 [2]: http://four.laravel.com/docs/schema # 열 추가
예를 들어 파일을 열 수 있는 기존 마이그레이션과 수정하십시오 됩니다 추가에는 테이블, 그리고 이 터미널 입력:
$ php artisan migrate:refresh
는 이 일에 대한 협력했습니다 라라벨 5.1.
첫째, 이 코드를 실행 상의 터미널
php artisan make:migration add_paid_to_users --table=users
그 후 파일, 디렉터리 데이터베이스의 백업이며 프로젝트에 디렉토리이며 검색하기를 확장하십시오 마이그레이션과 편집하십시오 add_paid_to_users.php 이 코드 추가
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->string('paid'); //just add this line
});
}
그 뒤로 돌아가서 터미널, 이 명령을 실행합니다.
php artisan migrate
ᄋ "이번 움말.
비록 다른 zone 에서 언급한 것처럼, best practice 마이그레이션과 파일은 유사 틴커 함께 열 추가할 수도 있습니다.
"' $ php 장인이 틴커 "'
"'php 테이블 스키마 (& # 39, users& # 39, 함수 (\illuminate\database\schema\blueprint $ table) 정수 (& # 39, paid& # 39;), {$ table->. }) "'
< br>; < br>; (여기서 포맷되었습니다 가독성을 위해 정보기술 (it) "'php 테이블 스키마 (& # 39, users& # 39, 함수 (\illuminate\database\schema\blueprint $ table) { 정수 (# 39, & # 39, paid&), $ table->. }). "'