ExpDev07
228
10
Eloquent

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'issuer' in 'field list'

Posted 3 weeks ago by ExpDev07

Hey, I am trying to create a model through seeding but is getting the following error:

Illuminate\Database\QueryException  : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'issuer' in 'field list' (SQL: insert into `warnings` (`message`, `issuer`, `player_id`, `updated_at`, `created_at`) values (Accusamus voluptas iure nobis eius ut. Recusandae possimus et ea dignissimos consequatur velit. Vel aliquam veritatis exercitationem quisquam aut. Fugit blanditiis dolores vel ut dolorem commodi est., {"id":1,"identifier":"steam:nonqui3491267","name":"Sabrina Sauer","identifiers":"[\"steam:nonqui3491267\", \"162.23.60.34\"]","playtime":1306,"seen":"2019-06-20 20:03:14","cid1":null,"cid2":null,"cid3":null,"cid4":null}, 1, 2019-06-20 20:03:14, 2019-06-20 20:03:14))

My seeder looks as following:

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    // Faker to create data.
    $faker = Factory::create();

    // And now, let's create a few users in our database:
    for ($i = 0; $i < 50; $i++) {
        // Create a user with some properties.
        $user = User::create([
            'identifier' => 'steam:' . $faker->word . $faker->word . $faker->numberBetween(0, 10000000),
            'username' => $faker->name,
            'avatar' => self::$AVATAR_URL
        ]);

        // An IP address.
        $ipAddress = $faker->ipv4;

        // Create a player for this user.
        $player = $user->player()->create([
            'name' => $user->username,
            'identifiers' => json_encode([ $user->identifier, $ipAddress ]),
            'playtime' => $faker->numberBetween(0, 10000),
            'seen' => Carbon::now()
        ]);

        // Give the player some warnings and self as issuer.
        $player->warnings()->create(
            [ 'message' => $faker->text, 'issuer' => $player ]
        );
    }
}

As you can see, I'm trying to create a new warning for the player, and just set the issuer as themselves. The player model has the following relationship:

/**
 * Gets the warnings that this person has received.
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasMany
 */
public function warnings()
{
    return $this->hasMany(Warning::class);
}

And the Warning model has the following relationships:

/**
 * Gets the player that received this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function player()
{
    return $this->belongsTo(Player::class);
}

/**
 * Gets the player that issued this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function issuer()
{
    return $this->belongsTo(Player::class);
}

As you can clearly see, there is an "issuer" which I am trying to set in the seeder. In the seeder, "player" and "issuer" should be the same Player. In the migration, I do have an unsigned big integer for the "issuer_id".

Any help would be greatly appreciated, thanks!

Please sign in or create an account to participate in this conversation.