例外" SQLSTATE [HY000] [1049]基础' symfony' inconnue"安装FOSUserBundle后更新架构

时间:2015-01-21 01:55:39

标签: symfony doctrine-orm fosuserbundle

我是初学者。我在Symfony 2.6.3上安装了FOSUserBundle,这本书是基于Symfony 2.0.10。我在407页面,目前还没有biger问题。

我坚持的练习是关于运行并测试新的Symfony-with-FOSUserBundle-version。

在运行命令doctrine:schema:update --force

时出现错误dipslay

[Doctrine\DBAL\Exception\ConnectionException] An exception occured in driver: SQLSTATE[HY000] [1049] Base 'symfony' inconnue

[Doctrine\DBAL\Driver\PDOException]SQLSTATE[HY000] [1049] Base 'symfony' inconnue

[PDOException]SQLSTATE[HY000] [1049] Base 'symfony' inconnue

以下是我在配置新的Symfony-with-FOSUserBundle-version时更改的文件 1。

 #\app\config\parameters.yml   
 parameters:
        database_driver: pdo_mysql
        database_host: localhost
        database_port: null
        database_name: symfony2sandbox
        database_user: editor
        database_password: secretPASSWORD
        mailer_transport: smtp
        mailer_host: localhost
        mailer_user: null
        mailer_password: null
        locale: en
        secret: ThisTokenIsNotSoSecretChangeIt

2

#\src\My\UserBundle\Entity\User.php
<?php

namespace My\UserBundle\Entity;

use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 * @ORM\Table(name="fos_user")
 */
class User extends BaseUser {

    /**
     * @ORM\Id
     * @ORM\Column(type="integer")
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    protected $id;

    public function __construct() 
    {
        parent::__construct();
    }

}

3

#\app\config\security.yml
security:
    providers:
        fos_userbundle:
            id: fos_user.user_manager

    encoders:
        FOS\UserBundle\Model\UserInterface: sha512

    firewalls:
        main:
            pattern: ^/
            logout: true
            anonymous: true
            form_login:
                provider: fos_userbundle
                csrf_provider: form.csrf_provider
                login_path: /login
                use_forward: false
                check_path: /login_check
                post_only: true
                always_use_default_target_path: false
                default_target_path: /
                target_path_parameter: _target_path
                use_referer: false
                failure_path: null
                failure_forward: false
                username_parameter: _username
                password_parameter: _password
                csrf_parameter: _csrf_token
                intention: authenticate

    access_control:
        - { path: ^/login$, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/register, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/resetting, role: IS_AUTHENTICATED_ANONYMOUSLY }
        - { path: ^/admin/, role: ROLE_ADMIN }

    role_hierarchy:
        ROLE_ADMIN: ROLE_USER
        ROLE_SUPER_ADMIN: ROLE_ADMIN

4

#\app\config\config.yml
imports:
    - { resource: parameters.yml }
    - { resource: security.yml }
    - { resource: services.yml }

framework:
    #esi:             ~
    translator:      ~
    secret:          "%secret%"
    router:
        resource: "%kernel.root_dir%/config/routing.yml"
        strict_requirements: ~
    form:            ~
    csrf_protection: ~
    validation:      { enable_annotations: true }
    templating:
        engines: ['twig']
        #assets_version: SomeVersionScheme
    default_locale:  "%locale%"
    trusted_hosts:   ~
    trusted_proxies: ~
    session:
        default_locale: pl
        # handler_id set to null will use default session handler from php.ini
        handler_id:  ~
    fragments:       ~
    http_method_override: true

# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"

# Assetic Configuration
assetic:
    debug:          "%kernel.debug%"
    use_controller: false
    bundles:        [ ]
    #java: /usr/bin/java
    filters:
        cssrewrite: ~
        #closure:
        #    jar: "%kernel.root_dir%/Resources/java/compiler.jar"
        #yui_css:
        #    jar: "%kernel.root_dir%/Resources/java/yuicompressor-2.4.7.jar"

# Doctrine Configuration
doctrine:
    dbal:
        driver:   "%database_driver%"
        host:     "%database_host%"
        port:     "%database_port%"
        dbname:   "%database_name%"
        user:     "%database_user%"
        password: "%database_password%"
        charset:  UTF8
        # if using pdo_sqlite as your database driver:
        #   1. add the path in parameters.yml
        #     e.g. database_path: "%kernel.root_dir%/data/data.db3"
        #   2. Uncomment database_path in parameters.yml.dist
        #   3. Uncomment next line:
        #     path:     "%database_path%"

    orm:
        auto_generate_proxy_classes: "%kernel.debug%"
        auto_mapping: true

# Swiftmailer Configuration
swiftmailer:
    transport: "%mailer_transport%"
    host:      "%mailer_host%"
    username:  "%mailer_user%"
    password:  "%mailer_password%"
    spool:     { type: memory }


stof_doctrine_extensions:
    default_locale: en_US
    orm:
        default:
            tree: false
            loggable: false
            timestampable: false
            sluggable: false
            translatable: false

fos_user:
    db_driver: orm
    firewall_name: main
    user_class: My\UserBundle\Entity\User

5

#\app\config\routing.yml
fos_user_security:
    resource: "@FOSUserBundle/Resources/config/routing/security.xml"

fos_user_profile:
    resource: "@FOSUserBundle/Resources/config/routing/profile.xml"
    prefix: /profile

fos_user_register:
    resource: "@FOSUserBundle/Resources/config/routing/registration.xml"
    prefix: /register

fos_user_resetting:
    resource: "@FOSUserBundle/Resources/config/routing/resetting.xml"
    prefix: /resetting

fos_user_change_password:
    resource: "@FOSUserBundle/Resources/config/routing/change_password.xml"
    prefix: /profile

重要的是: 不是\config\parameters.yml的相关内容。这些错误也发生在早期版本的Symfony-without-FOS的parameters.yml设置中,效果很好。

来自sql命令的数据库:

drop schema if exists symfony2sandbox;
create schema symfony2sandbox default character set utf8 collate utf8_polish_ci;
grant all on symfony2sandbox.* to editor@localhost identified by 'secretPASSWORD';
flush privileges;

1 个答案:

答案 0 :(得分:0)

解决方法:

  1. 在config.yml注释行中 # default_locale: pl

  2. 在\ src \ My \ UserBundle \ Entity \ User.php中将行use FOS\UserBundle\Entity\User as BaseUser;更改为use FOS\UserBundle\Model\User as BaseUser;

  3. 在我的书中可能写错字,也许是过时的差异。 (2012年以来的书。)