Laravel logo Laravel5.2 Documentation Laracasts Forge News Ecosystem Conference Community HomeLaracastsForgeNewsEcosystem Conference Community DocumentationPrologueRelease NotesUpgrade GuideContribution GuideAPI DocumentationSetupInstallationConfigurationHomesteadValetTutorialsBasic Task ListIntermediate Task ListThe BasicsRoutingMiddlewareControllersRequestsResponsesViewsBlade TemplatesArchitecture FoundationsRequest LifecycleApplication StructureService ProvidersService ContainerContractsFacadesServicesAuthenticationAuthorizationArtisan ConsoleBillingCacheCollectionsElixirEncryptionErrors & LoggingEventsFilesystem / Cloud StorageHashingHelpersLocalizationMailPackage DevelopmentPaginationQueuesRedisSessionSSH TasksTask SchedulingTestingValidationDatabaseGetting StartedQuery BuilderMigrationsSeedingEloquent ORMGetting StartedRelationshipsCollectionsMutatorsSerializationPrologueRelease NotesUpgrade GuideContribution GuideAPI DocumentationSetupInstallationConfigurationHomesteadValetTutorialsBasic Task ListIntermediate Task ListThe BasicsRoutingMiddlewareControllersRequestsResponsesViewsBlade TemplatesArchitecture FoundationsRequest LifecycleApplication StructureService ProvidersService ContainerContractsFacadesServicesAuthenticationAuthorizationArtisan ConsoleBillingCacheCollectionsElixirEncryptionErrors & LoggingEventsFilesystem / Cloud StorageHashingHelpersLocalizationMailPackage DevelopmentPaginationQueuesRedisSessionSSH TasksTask SchedulingTestingValidationDatabaseGetting StartedQuery BuilderMigrationsSeedingEloquent ORMGetting StartedRelationshipsCollectionsMutatorsSerializationDatabase: MigrationsIntroductionGenerating MigrationsMigration StructureRunning MigrationsRolling Back MigrationsWriting MigrationsCreating TablesRenaming / Dropping TablesCreating ColumnsModifying ColumnsDropping ColumnsCreating IndexesDropping IndexesForeign Key ConstraintsIntroductionMigrations are like version control for your database, allowing a team to easily modify and share the application's database schema. Migrations are typically paired with Laravel's schema builder to easily build your application's database schema.The Laravel Schema facade provides database agnostic support for creating and manipulating tables. It shares the same expressive, fluent API across all of Laravel's supported database systems.Generating MigrationsTo create a migration, use the make:migration Artisan command:php artisan make:migration create_users_tableThe new migration will be placed in your database/migrations directory. Each migration file name contains a timestamp which allows Laravel to determine the order of the migrations.--Bàn và tạo ra tùy chọn cũng có thể được sử dụng để chỉ ra tên của các bảng và cho dù quá trình di chuyển sẽ tạo ra một bảng mới. Các tùy chọn này chỉ đơn giản là trước khi điền vào tập tin ngẫu nhiên tạo ra di chuyển với các bảng quy định:php nghệ nhân thực hiện: di chuyển add_votes_to_users_table--bàn = người dùngphp nghệ nhân thực hiện: di chuyển create_users_table--tạo = người dùngNếu bạn muốn chỉ định một đường dẫn đầu ra tùy chỉnh cho quá trình di chuyển tạo ra, bạn có thể sử dụng--con đường lựa chọn khi thực hiện lệnh thực hiện: di chuyển. Đường dẫn cung cấp nên tương đối so với đường cơ sở ứng dụng của bạn.Cấu trúc di chuyểnMột lớp học di chuyển có hai phương pháp: lên và xuống. Phương pháp lên được sử dụng để thêm mới bảng, cột, hoặc các chỉ số cơ sở dữ liệu của bạn, trong khi các phương pháp xuống nên chỉ đơn giản là đảo ngược hoạt động thực hiện bằng phương pháp lên.Trong cả hai của những phương pháp này bạn có thể sử dụng xây dựng lược đồ Laravel nhiệm tạo ra và sửa đổi các bảng. Để tìm hiểu về tất cả các phương pháp có sẵn trên các xây dựng lược đồ, hãy kiểm tra tài liệu hướng dẫn của nó. Ví dụ, hãy xem di chuyển mẫu mà tạo ra một bảng vé máy bay:sử dụng IlluminateDatabaseSchemaBlueprint;sử dụng IlluminateDatabaseMigrationsMigration;lớp CreateFlightsTable kéo dài di chuyển{ /** * Chạy các quá trình di chuyển. * khoảng trống * @return */ khu vực chức năng up() { Schema::Create ('chuyến bay', chức năng (Blueprint $table) {} $table -> increments('id'); $table -> string('name'); $table -> string('airline'); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::drop('flights'); }}Running MigrationsTo run all outstanding migrations for your application, use the migrate Artisan command. If you are using the Homestead virtual machine, you should run this command from within your VM:php artisan migrateIf
đang được dịch, vui lòng đợi..
