Home » Php » On server my application is looking for uppercase table name instead of lowercase

On server my application is looking for uppercase table name instead of lowercase

Posted by: admin October 29, 2017 Leave a comment

Questions:

I have this table on my local xampp , the table name is tags , this works perfectly fine on my local system, but when I upload this table to my server I get the following error:

enter image description here

The tables I have under the table peckinga_blog are the following:

enter image description here

As you can see tags is one of them , Also for the tags table I have the following migrations in my laravel application:

<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('Tags', function (Blueprint $table) {
            $table->increments('id');
            $table->mediumText('tag');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('Tags');
    }
}

Now why am I getting this this error in spite of my database clearly being available ? What can I do so that my server will look for the database tags instead of Tags ?

Answers:

Database and table names are not case sensitive in Windows, and case sensitive in most varieties of Unix or Linux. Table names in MySQL are file system entries, so they are case insensitive if the underlying file system is.

Although after applying the migration, it should work But in case if it is not working and you want both statements i.e. lower case and upper case name in table to succeed, you need to put the following line

lower_case_table_names = 1

in your /etc/my.cnf or wherever you keep your MySQL configuration.

Doctrine generated capital/CamelCase table names and MySQL stored them as lowercase!

Or

  1. Before export the database from local you can do these steps:

  2. open your MySQL configuration file: [drive]\xampp\mysql\bin\my.ini

  3. look up for: # The MySQL server [mysqld]

  4. add this right below it: lower_case_table_names = 2

  5. save the file and restart MySQL service

Be sure to add the system variable to [mysqld] section of the configuration file.

For more information you can check the MySQL Reference Link.

Questions:
Answers:

I had the following line in my code:

    $tags = DB::table('Tags')->get();

worked perfectly locally on my windows XAMPP, but needed to change it to:

    $tags = DB::table('tags')->get();

to work on my server.

Questions:
Answers:

the case sensitivity depends on your underlying filesystem, which explains the discrepancy between your local and production machine.

since this is a common problem, I’d recommend to use lowercase allover as a convention. change your Tags to tags in your migrations and also in your model and you should be good to go.

if you need to rename your table, rename it first to something_else, and than again to tags.