Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Error upon submitting the /user/create form: "Unknown column 'password_confirmation" #10

Closed
ghost opened this issue Feb 14, 2013 · 13 comments

Comments

@ghost
Copy link

ghost commented Feb 14, 2013

Upon submitting the form to create a new user (/user/create), the following fatal error is returned:

    Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_confirmation' in 'field list' (SQL: insert into `users` (`username`, `email`, `password`, `password_confirmation`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?))

and no new user is added to the database.

@andrew13
Copy link
Collaborator

Have you done a composer update lately? The model removes the password_confirmation field before the save.

    /**
     * Ardent method overloading:
     * Before save the user. Generate a confirmation
     * code if is a new user.
     *
     * @param bool $forced Indicates whether the user is being saved forcefully
     * @return bool
     */
    public function beforeSave( $forced = false )
    {
        if ( empty($this->id) )
        {
            $this->confirmation_code = md5(microtime().static::$_app['config']->get('app.key'));
        }

        /*
         * Remove password_confirmation field before save to
         * database.
         */
        if ( isset($this->password_confirmation) )
        {
            unset( $this->password_confirmation );
        }

        return true;
    }

https://github.com/Zizaco/confide/blob/master/src/Zizaco/Confide/ConfideUser.php

@Zizaco
Copy link
Owner

Zizaco commented Feb 14, 2013

@j20, If you override the method beforeSave of your model, make sure to call parent::beforeSave( $forced ) in it.

@Zizaco Zizaco closed this as completed Feb 14, 2013
@ghost
Copy link
Author

ghost commented Feb 14, 2013

Hmm. I haven't overridden anything. My User.php model is empty. I've just followed the Confide instructions:

<?php

use Zizaco\Confide\ConfideUser;

class User extends ConfideUser {

}

I suppose I can try Confide with a different L4 installation and see if it still happens.

@Zizaco
Copy link
Owner

Zizaco commented Feb 15, 2013

Please let me know if the error persists

@ghost
Copy link
Author

ghost commented Feb 15, 2013

Sorry, I'm getting the same error when trying to create a new user. I set up a new Laravel 4 (beta 3) installation and downloaded the current version of Confide and set it up. I also tried using Confide's restful controller and restful route, but received the same error again.

Exception: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'password_confirmation' in 'field list' (SQL: insert into `users` (`username`, `email`, `password`, `password_confirmation`, `updated_at`, `created_at`) values (?, ?, ?, ?, ?, ?))

This likely doesn't help much, but after some playing around, I've discovered that if I comment out Line 38 of UserController.php $user->password_confirmation = Input::get( 'password_confirmation' ); that I can create a new account and it is saved to the database, but then no fields are validated and the password isn't hashed.

So I take it that you are able to create an account on your installation?

@andrew13
Copy link
Collaborator

Can you manually add a couple var_dumps() within the https://github.com/Zizaco/confide/blob/master/src/Zizaco/Confide/ConfideUser.php

Something like this:

public function beforeSave( $forced = false )
    {
        if ( empty($this->id) )
        {
            $this->confirmation_code = md5(microtime().static::$_app['config']->get('app.key'));
        }
        echo "password dump::";
        var_dump($user->password_confirmation);

        echo "pre isset/unset
";
        /*
         * Remove password_confirmation field before save to
         * database.
         */
        if ( isset($this->password_confirmation) )
        {
            unset( $this->password_confirmation );
        }
        echo "password::";
        var_dump($user->password_confirmation);

        echo "post isset / unset
";
die();

        return true;
    }

Then post the results.

@ghost
Copy link
Author

ghost commented Feb 15, 2013

Ok. I pasted those echo's and var_dump's into ConfideUser.php, but I get the same error message upon submission and do not see any of the echo'd output.

It seems that beforeSave is not being run because I can use var_dump($user->password_confirmation); exit; within UserController's postIndex() and I do see that it contains the expected value. But using var_dump within the beforeSave is not working. I see no output from it. ... Also, I just noticed that the confirmation_code column of the database is empty and it should have a value if beforeSave() were being run.

So I have to figure out why beforeSave() isn't being run.

@Zizaco
Copy link
Owner

Zizaco commented Feb 16, 2013

I'm sorry but I couldn't reproduce this error here.

Can you please put a sample project with this error in github for us to examine?

@andrew13
Copy link
Collaborator

An upload of your exact files to github would be ideal as I cannot reproduce either. More detail could help as well.
What environment are you running: Linux / Windows?
What Distro / Version?
Localhost / shared server / VPS / etc?
Version of PHP?
Version of MySQL?
Apache / nginx / lighttpd?

@ghost
Copy link
Author

ghost commented Feb 18, 2013

A fresh install of Laravel 4 beta 4 and Confide today has it working! I have no idea what was the cause. But thanks for helping troubleshoot it guys!

@Zizaco
Copy link
Owner

Zizaco commented Feb 18, 2013

Your welcome :)

@andrew13
Copy link
Collaborator

Welcome!

@jasonagnew
Copy link

Incase anyone ever comes across this again its caused by not extending the User model to:

class User extends ConfideUser {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants