I tried to create a new Laravel app via laravel new <app name> and use the built-in Laravel authentication make:auth.
But I can't make it work when I change the id column is not in my table.
The "ID" that I am using has a different column name, it is StaffID.
How could make it work? I don't see an id in my login code ( make:auth ).
Thank you.
Change the Primary Key associated with the Model
You have changed the name of the Primary Key on the database but Laravel by default makes an assumption that every table has a Primary Auto Incrementing Key of "id". There are many reasons for this, the most important being that it's standard practice to have this and it means you don't need to declare it on every model.
However, as you have changed your primary key from id to StaffID, Laravel needs to also be aware of this change to the Database. What you need to do is add the following to the users model directly within the Class:
protected $primaryKey = 'StaffID ';
Related
I am Trying to Create a CRUD operations using mvc and wcf and entity framework
When I try to add a new form does not work and no error message appears.
But the edit and delete operations are working fine. Only it's not creating the new form that time the id value is 0 it's not getting an ID value.
I am trying more times.but it's not getting proper solutions. So Give me one Solution
I published the project on public website if you want to check.
Link: http://s000.tinyupload.com/index.php?file_id=40899801495052398066
The database name is "mydemo"
Thanks,
Pari
Based on your EDMX model Id's Store Generated Pattern is not set to Identity.
but since your sql query for creating Table has Identity for Id column, I suggest removing your EDMX and create it again.
Id column in database should be primary key. If a column is identity and is not primary key, Its value is showing 0.
How can I change the field name of Django's autoincrement from id to something like tablename_id?
I want to do it in the model definition itself.
The autoincrement key is created automatically do there doesn't seem a way to set it via the db_column attribute.
class ModelTest(models.Model):
tablename_id = models.AutoField(primary_key=True)
I hope I've helped.
Anybody knows how to map grails domain class to MSSQL entity witch has not primary key
class BRCategoryInt {
String lang
String name
static hasMany = [category: BRCategory]
static constraints = {
}
static mapping = {
table "brCategoryInt"
version false
//id column: ""
category column: "CategoryId"
lang column: "Lang"
name column: "Name"
}
}
In legacy database we have not primary key, just have an one FK CategoryId.
Any help will be very appreciated.
You should really always have a primary key on your data and I would recommend adding one just to keep everyone happy. If you cannot simply add a auto-increment id to your table you could use a composite key. See documentation here. If you cannot do this either then I would consider re-thinking how youe data is laid out.
You cannot map such domain in Grails. To read/write such legacy tables try groovy Sql.
It is my understanding that in theory it is possible to map to a table without a primary key, however I have yet to see it actually done. I have struggled with attempting it for days with nothing to show.
Short answer: Not possible in the current version of Grails.
I have a web app which I can create some notes, each time I create a new note, it will insert to a table with an auto_increment id. (quite obvious)
Now I want to develop an android app which I can create notes too (save them locally in sqlite), and then syncronize those notes with the server.
The problem is, when I create notes in my phone they will have their own auto_increment id which many times will be the same with those notes in server!
I don't care to have duplicated notes (actually I don't think there is a way to differentiate if the new note is duplicated or not, because they don't have some physical id), the problem is if they have same id (primary key), I won't be able to insert them to the server.
Any suggestion?
You could use an UUID as a key for your note.
That way, each entry should have an unique id, be it created on the server or on the client.
To create a UUID, you can use UUID.randomUUID().
The most obvious solution would be to give each note its own unique hash or GUID in addition to the database's auto_increment_id.
You'd then use these unique values as the basis for synchronisation in conjunction with a "last synced" timestamp in each of the tables so that you know what data needs to be synced and can easily determine if the data already exists in the destination (and should be updated) or whether it's a new note.
I'm sorry but i think that your DB structure is wrong. You cannot use autoincrement field in this way, different DBs with a disconnected architecture. Autoincrement values are created for a specific use, if you need to merge two tables like this, you have to implement a different logic. Use a note_id to identify a note in a unique way, using more data (i.e. the user id, the device id etc.) to make this id unique. Autoincrement will only give you a messy architecture at best in this scenario
I have a Dynamic Data Entities Web Application that uses a database with GUIDs as primary keys for tables. All of the GUID fields have the default value set to NEWID() so SQL Server will generate a new GUID for any record. However in my dynamic data web site, in the insert new entry pages the GUID field shows up and it is expected for the user to enter data. How could I prevent the field from being displayed?
According to MSDN:
"You can hide the primary key as you do any other column by using the Scaffold attribute and setting its value to false. Because automatically generated keys are not recognized, the default Insert page templates do not work with EDM for tables that have automatic primary keys unless you create a partial class for the entity and apply the Scaffold attribute with a value of false."
Also, as an aside it's preferable to use "newsequentialid()" for the default value of Guid if you're using SQL Server 2005 or higher as it's more efficient for inserting.
Not the right Answer..
After doing this, which I did, you can insert 1 record which will get a GUID with all zero's. After that you will get no error message at all, but you will be unable to insert any more records, because of the unique index constraint on the guid ( which is a primary key of course ).
To really solve this problem, you have to edit the emdx file and add the
StoreGeneratedPattern="Identity"
into your Guid property tag under the "SSDL content" comment. Example:
<Property Name="Guid" Type="uniqueidentifier" Nullable="false" StoreGeneratedPattern="Identity"/>
If yhou do this in the designer within visual studio it will annotate the property tag under the "CSDL content" comment which doesn't work..
Used Entity Framework 4.0 Visual studio 10 and .NET framework 4.0