Skip to content
This repository has been archived by the owner on Feb 18, 2022. It is now read-only.

Column not found: 1054 Unknown column 'theme' in 'field list' #36

Open
BrendanBasson4 opened this issue Feb 15, 2022 · 0 comments
Open

Comments

@BrendanBasson4
Copy link

When initialising the settings I get this error:

Column not found: 1054 Unknown column 'theme' in 'field list' (SQL: insert into user_settings (settable_id, settable_type, metadata_id, theme, updated_at, created_at) values (1, App\Models\Company, 1, dark, 2022-02-15 10:01:07, 2022-02-15 10:01:07))

users.php:

Setting::name('display_name')->boolean()->default(false);

Setting::name('theme')->array()->default(['theme' => 'dark'])->group('companies')->bag('companies');

Initialization:

$user = User::first();
    
$user->company->settings()->initialize();

$user->settings()->initialize();

I'm initialising because I use a seeder to create the models.

I have migrated the settings and company is another model connected to user model by foreign ID.

User model:

namespace App\Models;

use Laravel\Sanctum\HasApiTokens;
use Illuminate\Notifications\Notifiable;
use DarkGhostHunter\Laraconfig\HasConfig;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasConfig;

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'company_id'
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array<int, string>
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array<string, string>
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function company()
    {
        return $this->belongsTo(Company::class);
    }
}

Company model:

namespace App\Models;

use DarkGhostHunter\Laraconfig\HasConfig;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Company extends Model
{
    use HasFactory, HasConfig;

    protected $fillable = [
        'name',
    ];
}

Am I missing something?

Note: I was able to create user settings but when I added company that's when the error started.

Versions:

  • "laravel/framework": "^8.75",
  • "darkghosthunter/laraconfig": "^1.3.5",
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant