Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 505 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Laravel 5.1 refresh and seed a single table

#1
I'm looking to refresh and seed a single table in Laravel 5.1. Is this even possible?

I have tried the below, but it gives an error (incorrect syntax).

php artisan migrate:refresh --path=database/migrations/CreateTableTimesheet

If I use: `php artisan migrate:refresh` it just says:

> Nothing to migrate
Reply

#2
Maybe first just backup the database, drop it and check if whole seeding, migrating and refreshing mechanic works. But first dump artisan autoload.
Reply

#3
You could use `migrate:refresh` command that will roll back all of your migrations and then execute the `migrate` command. This command effectively re-creates your entire database :

php artisan migrate:refresh

And you may use the `--class` option to specify a specific seeder class to run individually :

php artisan db:seed --class=UserTableSeeder

The full code will be :

php artisan migrate:refresh
php artisan db:seed --class=UserTableSeeder

Hope this helps.
Reply

#4
Its better to truncate your same table first and then seed:-

public function run()
{
Table::truncate();
//seed your table here
}

then you can run your same seeder like this:-

php artisan db:seed --class=YourSeeder
Reply

#5
```
php artisan tinker
```

```

>>> App\Status::truncate()

```

Will clear the statuses table

So you can do
```

>>> App\{MODEL_CLASS}::truncate()

```


--------------------------------------------

I found this quite useful when I don't want to clear all the tables, especially users.
Reply

#6
I don't think any answer so far addresses the question of migrating and seeding a **single** table. So, given the migration file `database/migrations/create_foo_table.php` and the seed file `database/seeds/FooTableSeeder.php`, which contains the `FooTableSeeder` seed class, you can do the following:

```
php artisan migrate:refresh --path=database/migrations/create_foo_table.php
php artisan db:seed --class=FooTableSeeder
```

This will rollback, migrate and seed your Foo table. See: [rolling back migrations][1] and [running seeders][2] in the Laravel 5.1 documentation (at the time of writing this, Laravel 7.x is out and the syntax has not changed).


[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#7
You can do it in two steps:

1. Refresh your specific table:
```
php artisan migrate:refresh --path=database/migrations/00_create_foo_table.php
```
2. Seed tables set in `database/seeds/DatabaseSeeder.php`:
```
composer dump-autoload
php artisan db:seed
```

**=== Extra information ===**

You can comment the seeders you don't want to use in `DatabaseSeeder.php`:
```
<?php

use Illuminate\Database\Seeder;

class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
$this->call([
FooSeeder::class,
// BarSeeder::class,
// UserSeeder::class,
]);
}
}
```
In this example, only `database/seeds/FooSeeder.php` will be passed.
Reply

#8
include full table name <br>
example
```
php artisan migrate:refresh --path='database/migrations/2014_10_12_000000_create_table_timesheet.php'
```
Reply

#9
Tips for run migration,roleback,refresh and seeder specific file for Laravel Framework

Migrate

php artisan migrate --path=/database/migrations/fileName.php

Roolback

php artisan migrate:rollback --path=/database/migrations/fileName.php

Refresh

php artisan migrate:refresh --path=/database/migrations/fileName.php

Seeder

php artisan db:seed --class=classNameTableSeeder

Thanks
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through