0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Laravel sqlite手始め備忘録(前も書いたけど)

0
Last updated at Posted at 2020-12-28

前にもララベルでのsqlite3の実行方法は書きましたが、改めてもう一度、まとめてといことで書きます。

sqliteのデータベースファイルの作成

まず、sqliteのデータベースのファイルの作成をします。Laravelのプロジェクトディレクトリに移動して、以下のコマンドでデータベースファイルを作成します。

ターミナル
$type database/database.sqlite

sqlite3ではデータベースを作成する際は、ファイルを作成するだけでいいようです。

Laravelの設定ファイル.envの編集

今度は、Laravelからsqlite3に接続する際の情報が記載されている.envファイルを編集します。
DB_CONNECTIONを書き換え以下はコメントアウトしておきます。

ターミナル
DB_CONNECTION=mysql → DB_CONNECTION=sqlite
# DB_HOST=127.0.0.1
# DB_PORT=3306
# DB_DATABASE=homestead
# DB_USERNAME=homestead
# DB_PASSWORD=secret

config/databaseの編集

今回自分はsqliteを利用するのでdafaultをmysqlからsqliteに変更します。
ターミナル
  'default' => env('DB_CONNECTION', 'mysql'), ⇒  'default' => env('DB_CONNECTION', 'sqlite'),

マイグレーションの実行

```terminal:ターミナル $php artisan migrate ```

実行結果

ターミナル
Migration table created successfully.
Migrating: 2014_10_12_000000_create_users_table
Migrated:  2014_10_12_000000_create_users_table
Migrating: 2014_10_12_100000_create_password_resets_table
Migrated:  2014_10_12_100000_create_password_resets_table

エラーが出なければOK。

間違っていることが大いにあり得るので賢い方ご指摘していただければと思います。よろしくお願いいたします。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?