-
Notifications
You must be signed in to change notification settings - Fork 90
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
RuntimeException table does not have a primary key #43
Comments
Can you post the table definitions of both the source and destination tables?
If it’s saying you don’t have a primary key, then I suspect that is the case for one of the tables...
Cheers
Joe Green
… On 29 Jul 2018, at 05:28, njovu ***@***.***> wrote:
My Table has a primary key, but when I run The DbSyn, it returns an error table does not have a primary key what can I do.
Thanks in advance
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
There is a lighter library I tried and it works on local host. The only limitation is that I failed to connect to the remote server!. This one looks the most awesome but have so far failed to use it. |
Looks like you have a mistake in your second “new Table()” line, where you’ve specified the database name in the table field. I think “db_spotout.test_table” should just be “test_table”
Cheers
Joe Green
… On 29 Jul 2018, at 14:00, njovu ***@***.***> wrote:
Step 1 **
**
Step 2
Step 3
Step 4
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
![step 5](https://user-images.githubusercontent.com/6410429/43368336-7e30a4d8-9329-11e8-8be6-04e84bc2607e.png)
I tried without and with the database concoction and it gave me same results
On Sun, Jul 29, 2018 at 12:12 PM, Joe Green <[email protected]>
wrote:
… Looks like you have a mistake in your second “new Table()” line, where
you’ve specified the database name in the table field. I think
“db_spotout.test_table” should just be “test_table”
Cheers
Joe Green
> On 29 Jul 2018, at 14:00, njovu ***@***.***> wrote:
>
> Step 1 **
>
> **
> Step 2
>
> Step 3
>
>
> Step 4
>
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub, or mute the thread.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#43 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGHQvQwYJGI10T8p_ZVzRTWgPpkikydIks5uLd8BgaJpZM4VlSI0>
.
|
Can you post a few lines of the data from the source table? What happens if you include both columns for syncing?
|
So the bit of code responsible for deciding the primary key is here: https://github.com/mrjgreen/db-sync/blob/v3/src/Table.php#L100 It's essentially running this query:
which should return a result set including the columns:
We transform this into an array sorted by the
If you could post the results of the query:
We should be able to figure out what's going wrong here... |
That is the result I get when I pass the query (SHOW INDEX FROM
db_timesheet.test_table WHERE `key_name` = 'PRIMARY')
…On Sun, Aug 5, 2018 at 12:25 PM Joe Green ***@***.***> wrote:
So the bit of code responsible for deciding the primary key is here:
https://github.com/mrjgreen/db-sync/blob/v3/src/Table.php#L100
It's essentially running this query:
SHOW INDEX FROM db_timesheet.test_table WHERE `key_name` = 'PRIMARY'
which should return a result set including the columns: Column_name,
Seq_in_index Eg:
Column_name Seq_in_index
Col1 0
Col2 1
We transform this into an array sorted by the Seq_in_index column:
[
0 => 'Col1',
1 => 'Col2'
]
If you could post the results of the query:
SHOW INDEX FROM db_timesheet.test_table WHERE `key_name` = 'PRIMARY'
We should be able to figure out what's going wrong here...
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#43 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AGHQvVClOxqBkRWFiAcOxhVeM0KMxmR8ks5uNxx2gaJpZM4VlSI0>
.
|
Where is the result? |
I’m sorry I think I’m going to struggle to diagnose this one.
The only thing I can suggest is that you have your connection/database/table names are incorrect and you are using dbsync against the wrong table... is this something you can double check?
I can’t see anything wrong with the code you have posted, but I can’t see a way that this error could be generated for any other reason than the primary key is missing from the table.
Cheers
Joe Green
… On 14 Aug 2018, at 11:58, njovu ***@***.***> wrote:
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks for the effort Joe, but unless you want me to share the whole credentials which I can, I have not missed any names. In-fact I used the same table name with two simple columns to make sure I get everything right! |
src/Table.php line : 98, add this line: $name = str_replace('"', '`', $name); |
Hi, I'm trying to use this packet but for some reason the code doesn't return no error but at the same time it doesn't work . error_reporting(E_ALL); require_once DIR . '/vendor/autoload.php'; use \DbSync\DbSync; $sync = new DbSync(new Transfer(new ShaHash(),1024,8)); $sync->dryRun(false); $sync->delete(false); $sourceConnection = new PDO('mysql:host=hostIp;dbname=dbName','dbName','password'); $sourceTable = new Table(new \Database\Connection($sourceConnection), 'aliapidemia', 'categories'); var_dump($sync->sync($targetTable, $sourceTable)); echo "done"; It only prints out "done" and doesn't do anything. |
I figured out the mistake, if you look at the command source, you'll see diff code:
You just have to use ConnectionFactory instead of \PDO |
thanks
…On Sat, May 25, 2019 at 3:34 AM Elias Farah ***@***.***> wrote:
I figured out the mistake, if you look at the command source, you'll see
diff code:
look some example:
require "vendor/autoload.php";
use Database\Connectors\ConnectionFactory;
use DbSync\DbSync;
use DbSync\Hash\ShaHash;
use DbSync\Table;
use DbSync\Transfer\Transfer;
$sync = new DbSync(new Transfer(new ShaHash()));
$sync->dryRun(false);
$source = createConnection('localhost', 'root', '', 'utf8');
$destination = createConnection('localhost', 'root', '', 'utf8');
$sourceTable = new Table($source, 'database1', 'table-origin');
$targetTable = new Table($destination, 'database2', 'table-destination');
$sync->sync($sourceTable, $targetTable);
function createConnection($host, $user, $password, $charset)
{
return (new ConnectionFactory())->make([
'host' => $host,
'port' => 3306,
'username' => $user,
'password' => $password,
'charset' => $charset,
'collation' => 'utf8_general_ci',
'driver' => 'mysql',
'options' => [
\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION,
\PDO::ATTR_DEFAULT_FETCH_MODE => \PDO::FETCH_ASSOC,
\PDO::ATTR_EMULATE_PREPARES => false,
]
]);
}
You just have to use ConnectionFactory instead of \PDO
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#43?email_source=notifications&email_token=ADSQJATKFMYCPMSMEBUXB4LPXBGO3A5CNFSM4FMVEI2KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWGQFRA#issuecomment-495780548>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ADSQJAUVK3WF6S3O2HWOTALPXBGO3ANCNFSM4FMVEI2A>
.
|
My Table has a primary key, but when I run The DbSyn, it returns an error table does not have a primary key what can I do.
Thanks in advance
The text was updated successfully, but these errors were encountered: